gpt4 book ai didi

android - 设置 ListView 的最大高度

转载 作者:太空宇宙 更新时间:2023-11-03 10:25:28 31 4
gpt4 key购买 nike

确实有些愚蠢,但我想为我的 ListView 设置最大高度,但我似乎找不到可行的方法。有人说要为 ListView 设置最大高度,但我找不到这个选项?我现在有

<?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_height="wrap_content".

编辑:您可以检查 ListView 中的项目数量并设置大小以防其高于 20。类似:

if(numberOfItems>20){
listview.setWidth(yourSize)
}

关于android - 设置 ListView 的最大高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13401562/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com