【发布时间】:2012-11-04 06:59:34
【问题描述】:
有些东西真的很愚蠢,但我想为我的列表视图设置一个最大高度,但我似乎找不到有用的东西。有人谈论为列表视图设置 maxheight,但我找不到这个选项? 我现在有
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="40dp" >
<ListView
android:id="@+id/lvSwitch"
android:layout_width="fill_parent"
android:layout_height="120dp" >
</ListView>
</LinearLayout>
但是当列表中只有一项时,它仍然有 120dp 的高度,那当然没有必要,它只是不能超过那个高度......
【问题讨论】:
-
您好,您应该使用 android:layout_weight="1" 作为列表视图,请看我的回答
-
@Talha 这在给定布局的上下文中无法实现。当 LinearLayout 中没有其他项时,layout_weight 无用。您至少需要两件物品才能达到预期的效果。