【发布时间】:2012-03-02 08:26:19
【问题描述】:
我有以下“按钮栏”布局设置:
<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>
我希望按钮栏(RelativeLayout)高度为屏幕高度的 10%,所以我使用 layout_weight="0.1" + layout_weight="0.9",但不超过 86 像素,所以我尝试使用 maxHeight ="86px",但这不起作用。
请问您知道如何实现 10% 的高度和恒定的最大高度布局限制吗?
【问题讨论】:
-
不幸的是,
RelativeLayout的 API 不包含属性maxHeight(View或ViewGroup也不包含)。这就是为什么它在你的代码中没有得到尊重,我认为。