Reputation: 1754
I have the following "button bar" layout setup:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/button_bar"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:maxHeight="86px"
android:orientation="horizontal">
<Button
android:id="@+id/home_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"/>
<Button
android:id="@+id/level_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/home_button"/>
<Button
android:id="@+id/help_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_toRightOf="@+id/level_button"/>
<Button
android:id="@+id/sound_button"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<View
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.9"/>
</LinearLayout>
I want the button bar (the RelativeLayout) height to be 10% of the screen height, so I used layout_weight="0.1" + layout_weight="0.9", but no more than 86 pixels, so I tried to use maxHeight="86px", but this doesn't work.
Do you have any clue how to achiveve 10% height combined with constant maximum height layout restriction, please?
Upvotes: 3
Views: 1371
Reputation: 20239
It is fairly easy and probably the cleanest solution to subclass LinearLayout
and create your own layout calculation.
Just override onLayout()
and onMeasure()
.
Upvotes: 1