0

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
Tvd
  • 4,463
  • 18
  • 79
  • 125
  • @jitendrasharma, Yes jitendra, that did the job. I have 3 btns in a Horizontal LinearLayout. At present I have set value to layout_width="78dip". I want it to use all the space available. If I put "WRAP_CONTENT" then only the size of text is the width of the btn. I want all btns of the row to be of same size & utilize all the width soace availble. Height is fine as I have used "fill_parent" for layout_height. Is there anything to set for width that will do the trick ? – Tvd Jan 07 '12 at 12:32

2 Answers2

2

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

jeet
  • 29,001
  • 6
  • 52
  • 53
  • for layout_height - fill_parent works rather than wrap_content. But facing a problem with it. Have a look at the updated question. – Tvd Jan 07 '12 at 17:10
  • Please let me know if you are still facing problem or it is fixed. – jeet Jan 09 '12 at 06:00
  • Thanks but that wraping & filling problem is solved. Now I am not able to find height of an layout in onCreate() - http://stackoverflow.com/questions/8784616/android-get-screen-size-for-the-root-layout-only See if you can guide with this. – Tvd Jan 09 '12 at 08:14
0

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

  row1 = (LinearLayout) findViewById(R.layout.mainrow1); 
kosa
  • 65,990
  • 13
  • 130
  • 167
  • In your code it is R.id.mainrow1 not R.layout.mainrow1. Please refer your posted code first line in findViewById method. – kosa Jan 07 '12 at 12:21
  • @thinksteep, jitendrasharma's option clean & build did the work. Thnaks – Tvd Jan 07 '12 at 12:42