I know that it is impossible to set percentages and that you can set a weight of certain images to scale their heights. What I am trying to do though is specify the height of a layout relative to the layout it is within. Basicly I have something like this
<LinearLayout android:layout_height="fill_parent"> <LinearLayout> </LinearLayout> </LinearLayout>
Of course this is a very simplified version, just so you can understand my gibberish. Basicly I want to set the inner linearlayout to be around 50% of the main linearlayout.
What is the best way to do this?
You can set android:weightSum="2" in the parent linear_layout and android:weight="1" in the inner linear_layout. Remember to set the inner linear_layout to fill_parent so weight attribute can work as expected.
android:layout_height. Specifies the basic height of the view. android:layout_width. Specifies the basic width of the view.
LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.
There is an attribute called android:weightSum.
You can set android:weightSum="2" in the parent linear_layout and android:weight="1" in the inner linear_layout.
Remember to set the inner linear_layout to fill_parent so weight attribute can work as expected.
Btw, I don't think its necesary to add a second view, altough I haven't tried. :)
<LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:weightSum="2"> <LinearLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="1"> </LinearLayout> </LinearLayout>
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