Setting the android build option programmatically

I am new to android. I want to know how to set parameters or attributes to layout x and layout y width and height from the program for any layouts such as absolute.

+4
android android-layout
Sep 19 '11 at 11:37
source share
2 answers

For a button, you can try the following:

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.

+12
Sep 19 '11 at 12:20
source share

if you set an identifier for your layout in this way

 <LinearLayout android:id="@+id/linear" /> 

then you can get the layout in the code this way.

 Linearlayout linear = (LinearLayout)findViewbyId(R.id.linear"); linear.setLayoutParams(new LayoutParams(arg0, arg1)); 

here in arg0 and arg1 you can pass the value of int, you can set the value below

 LayoutParams.FILL_PARENT LayoutParams.WRAP_CONTENT 
+1
Sep 19 '11 at 11:44
source share



All Articles