Android实现子View高度自适应最高子View的方案求助
Android实现多子View等高(由最高子View动态决定高度)
我想在Android平台实现一个在iOS上相对容易搞定的功能:让多个子View拥有相同的高度,而且这个高度得由运行时高度最高的那个子View来决定。
之前我找到过一个类似的问题,但那个方案是基于Button实现的,我猜这可能就是我自己试的方案无效的原因。
我目前用的示例布局代码是这样的:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:baselineAligned="false"> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <!--Other views--> </LinearLayout> <LinearLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" > <!--Other views--> </LinearLayout> </LinearLayout>
我优先希望能通过布局设计器直接实现这个功能,如果实在做不到,也接受用代码实现的方案——也就是先找到高度最高的子View,再把其他子View的高度都设置成这个值。
更新:我画了两张图来更清楚地说明问题:灰色区域是父LinearLayout,绿色区域是子LinearLayout,红色区域就是布局注释里的“Other views”。
实际效果图:
预期效果图:
内容的提问来源于stack exchange,提问作者Gustavo Baiocchi Costa
相关产品推荐
相关产品推荐

