Android LinearLayout子视图-所有视图应具有相同的高度,并且至少包装其内容
下面是我的(简化)代码示例:Android LinearLayout子视图-所有视图应具有相同的高度,并且至少包装其内容,android,android-linearlayout,Android,Android Linearlayout,下面是我的(简化)代码示例: <LinearLayout android:id="@+id/llCustomValueContainer" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="horizontal"> <LinearLayout
<LinearLayout
android:id="@+id/llCustomValueContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/llTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<!-- some content of undefined height -->
</LinearLayout>
<!-- following content is of undefined height as well -->
<TextView
android:id="@+id/tvValueTop"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"/>
</LinearLayout>
我想要什么
应该从它的最高子级(llCustomValueContainer
和llTitle
)派生出它的high值tvValueTop
和llTitle
应该具有相同的高度(因为我希望选择器和触摸使用全高),并且至少应该包装其内容tvValueTop
只要
llTitle
的高度高于tvValueTop
的高度,一切都可以正常工作。我能否以某种方式更改布局,使IllTitle
和tvValueTop
具有相同的高度,并至少包装其内容(应拉伸较小的视图,使其具有与较大视图相同的高度)?我不希望它们看起来高度相同(例如,将较小的一个垂直居中),但我确实希望它们具有相同的高度,因为两个视图都可以单击。对于外部的线性布局,使用包裹内容的高度,并为两个孩子使用高度match_parent
我知道这似乎有点奇怪,但只要外部线性布局的孩子中没有一个有确定的大小(固定或包裹内容
),结果就是每个孩子都是最高的孩子的身高
为什么不在文本视图中使用android:layout\u weight=“1”我不明白你的问题。您说两个子布局的高度应该相同,但您也说父布局的高度应该从其最高子布局的高度派生。你能再解释一下吗?谢谢,我完全忘了。。。这很有效