Change linear layout top margin programmatically android

后端 未结 7 1200
难免孤独
难免孤独 2021-02-01 02:31

i have two linear layouts in one frame layout.



        
7条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 03:04

    This updates the top margin without the need to update the other margin values.

    LinearLayout layout = (LinearLayout) findViewById(R.id.your_linear_layout);
    LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams();
    layoutParams.topMargin = 200;
    layout.setLayoutParams(layoutParams);
    

提交回复
热议问题