【发布时间】:2018-01-06 14:02:05
【问题描述】:
这是我的(简化的)代码示例:
<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和tvValueTop)推导出它的高度 -
llTitle和tvValueTop应该有相同的高度(因为我希望选择器和触摸使用全高)并且至少应该包装它们的内容
问题
只要llTitle 的高度高于tvValueTop 的高度,一切正常。我可以以某种方式更改布局,以便我 llTitle 和 tvValueTop 具有相同的高度并至少包裹它们的内容(较小的视图应该被拉伸到与较大的视图具有相同的高度)?我不希望它们看起来具有相同的高度(例如,通过将较小的垂直居中),但我真的希望它们具有相同的高度,因为可以单击两个视图。
【问题讨论】:
-
为什么不在 TextView 中使用 android:layout_weight="1"
-
我不明白你的问题。你说两个孩子应该有相同的高度,但你也说你的父布局应该从它的最高子布局的高度派生它的高度。你能解释一下吗?
标签: android android-linearlayout