gpt4 book ai didi

android - 结合 layout_weight 和 maxHeight?

转载 作者:太空狗 更新时间:2023-10-29 14:28:42 27 4
gpt4 key购买 nike

我有以下“按钮栏”布局设置:

<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% 的高度吗?

最佳答案

子类化 LinearLayout 并创建您自己的布局计算相当简单,可能是最干净的解决方案。

只需覆盖 onLayout()onMeasure()

关于android - 结合 layout_weight 和 maxHeight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9218112/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com