【发布时间】:2018-06-02 02:35:43
【问题描述】:
我正在尝试将在 ios 上非常容易的东西复制到 android。
我想要在运行时确定高度的相同高度的视图。视图的高度应以高度最大的视图为准。
我发现了一个类似的问题 (link),但它是基于按钮的,这可能是我的解决方案不起作用的原因。
例子:
<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>
也许有一个使用设计器的解决方案。 如果不可能,我认为我可能必须通过找到最大高度然后将高度分配给其他视图来以编程方式进行操作(如果您知道该怎么做,我也会接受它作为有效答案) .
更新:
我画了两张图片来说明我的问题。灰色区域是父线性布局。孩子们线性布局的绿色区域。红色区域是上面布局中注释的“其他视图”。
【问题讨论】:
-
你能发布预期的输出图像吗?
android:layout_weight可以是一个解决方案。 -
好的,我会这样做的
-
你愿意使用约束布局,而不是线性布局吗?
-
如果它有效,为什么不呢