Create Layout Programmatically in android - issue

前端 未结 2 836
死守一世寂寞
死守一世寂寞 2021-02-20 14:10

I am creating FrameLayout dynamically using the following code

mylayout.java

FrameLayout layout = new FrameLayout(this);
FrameLayout.LayoutParams layoutp         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-20 14:33

    Add

    layout.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
    

    or

    layout.setGravity(Gravity.CENTER);
    

    You forgot to set the gravity of the layout.

提交回复
热议问题