我知道设置百分比是不可能的,您可以设置某些图像的权重来缩放它们的高度。我正在尝试做的是指定布局相对于其所在布局的高度。基本上我有这样的东西
<LinearLayout android:layout_height="fill_parent">
<LinearLayout>
</LinearLayout>
</LinearLayout>
当然,这是一个非常简化的版本,只是为了让你能理解我的胡言乱语。基本上我想将内部线性布局设置为主要线性布局的 50% 左右。
最好的方法是什么?
最佳答案
有一个属性叫做android:weightSum。
您可以在父 linear_layout 中设置 android:weightSum="2",在内部 linear_layout 中设置 android:weight="1"。
记得将内部的 linear_layout 设置为 fill_parent 以便 weight 属性可以按预期工作。
顺便说一句,我认为没有必要添加第二个 View ,尽管我没有尝试过。 :)
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:weightSum="2">
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_weight="1">
</LinearLayout>
</LinearLayout>
关于Android 百分比布局高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6203609/