【发布时间】:2016-10-03 05:59:51
【问题描述】:
我有一个线性布局,其中包含两个列表视图、一个文本视图和另一个用于容纳一些按钮的线性布局。我希望第二个列表视图的高度是第一个的两倍。我已将两个列表视图的高度设置为 0dp,并将第一个 layout_weight 设置为 1,第二个设置为 2,然后将包含视图的 weightSum 设置为 3。这是实际布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:weightSum="3"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/categoryList" />
<ListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:id="@+id/itemList" />
<TextView
android:id="@+id/walletStr"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/cancelBtn"
android:text="cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/buyBtn"
android:text="buy"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
在模拟器上,这会产生预期的效果,但在实际设备上,几乎所有空间都到了顶部列表视图。
有什么想法吗?提前致谢。
【问题讨论】:
-
去掉
weightSum外层LinearLayout的属性。
标签: android android-linearlayout