Tvd
Tvd

Reputation: 4601

Android: Retrieve layout_marginBottom programmatically?

In my a LinearLayout I have set android:layout_marginBottom in my XML. I just want to retrieve that value.

Just LayoutParams doesn't give me access to bottomMargin . I tried to typecast :

row1 = (LinearLayout) findViewById(R.id.mainrow1); 
LinearLayout.LayoutParams row1Params = (android.widget.LinearLayout.LayoutParams) row1.getLayoutParams();

but this gives me Runtime exception ClassCastException.

The main aim is I got buttons in nested LinearLayouts & I want to set height/width of LinearLayout programmatically that will inturn auto set height of buttons. I have added bottomMargin after 1st layout - so there is space between 2 rows.

Upvotes: 0

Views: 843

Answers (2)

jeet
jeet

Reputation: 29199

Change Your layout of Button according to following logic,

set Layout_Width to 0dip set Layout_Weight to 1 set Layout_Height to Wrap_Content

Upvotes: 2

kosa
kosa

Reputation: 66647

try this. When you get layout, R.layout. is best option. It is working for me.

  row1 = (LinearLayout) findViewById(R.layout.mainrow1); 

Upvotes: 0

Related Questions