How to lay out Views in RelativeLayout programmatically?

前端 未结 9 1762
心在旅途
心在旅途 2020-11-22 15:04

I\'m trying to achieve the following programmatically (rather than declaratively via XML):


   

        
9条回答
  •  萌比男神i
    2020-11-22 15:51

    Try:

    EditText edt = (EditText) findViewById(R.id.YourEditText);
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams
        (
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT
        );
    lp.setMargins(25, 0, 0, 0); // move 25 px to right (increase left margin)
    edt.setLayoutParams(lp); // lp.setMargins(left, top, right, bottom);
    

提交回复
热议问题