I am new to android. I want to know how to set the parameters or attributes to layout x and layout y width and height from the program for any layouts like absolute.
For button you can try like this:
RelativeLayout.Layoutparams params = (RelativeLayout.LayoutParams)button.getLayoutParams();
params.setMargins(5, 5, 5, 5);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
button.setLayoutParams(params);
you have setMargins() to which you pass the left, top, right and bottom values respectively.
if you set the id for you layout like this way
<LinearLayout android:id="@+id/linear" />
then you can get the layout in code like this way.
Linearlayout linear = (LinearLayout)findViewbyId(R.id.linear");
linear.setLayoutParams(new LayoutParams(arg0, arg1));
here in arg0 and arg1 you can pass the int value of you can set the below value
LayoutParams.FILL_PARENT
LayoutParams.WRAP_CONTENT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With