[英]How to tell layout to space everything 50/50?
I have a vertical linear layout with two ListViews. 我有一个带有两个ListView的垂直线性布局。 I want the top ListView to take up 50% of the screen.
我希望顶部的ListView占据屏幕的50%。 I want the bottom listivew to take up 50% of the screen.
我希望底部的列表框占据屏幕的50%。 How can I do this in XML?
如何在XML中做到这一点?
The following layout should work 以下布局应该有效
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
How this works: 工作原理:
wrap_content
) is divided up between all the views with no height and a layout_weight
wrap_content
的视图,所以全部都被划分为所有没有高度的视图和layout_weight
(layout_weight of View) / (Sum of layout_weights in parent ViewGroup)
(layout_weight of View) / (Sum of layout_weights in parent ViewGroup)
视图的(layout_weight of View) / (Sum of layout_weights in parent ViewGroup)
(Sum of layout_weights in parent ViewGroup) = 2
and (layout_weight of View) = 1
for each ListView
, so each ListView
occupies 1/2
of the available space ListView
(layout_weight of View) = 1
(Sum of layout_weights in parent ViewGroup) = 2
(layout_weight of View) = 1
和(Sum of layout_weights in parent ViewGroup) = 2
并且(layout_weight of View) = 1
,因此每个ListView
占用可用空间的1/2
将Vertical LinearLayout设置为具有height:fill_parent
,然后将weight of each ListView to "1" eg android:layout_weight="1"
的weight of each ListView to "1" eg android:layout_weight="1"
设置weight of each ListView to "1" eg android:layout_weight="1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.