Change linear layout top margin programmatically android

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

i have two linear layouts in one frame layout.



        
7条回答
  •  名媛妹妹
    2021-02-01 03:06

    I have set up margins directly using below code (I tried using LinearLayout.LayoutParams but is was not working for me)

    LinearLayout layout = (LinearLayout)findViewById(R.id.yourrelative_layout);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
    params.setMargins(3, 300, 3, 3); 
    layout.setLayoutParams(params);
    

    Only this here is to notice that LayoutParams should be imported for following package android.widget.RelativeLayout.LayoutParams unless you will hit error.

提交回复
热议问题