java Android ListView仅显示第一项
我有一个只显示一个项目的列表视图。如果我将ListView设置为一个设置的高度,我可以看到所有的项目都被加载到其中,但是wrap_内容只显示第一行
<LinearLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:orientation="vertical">
<com.fmsirvent.ParallaxEverywhere.PEWImageView
安卓:id="@+id/logo"
安卓:layout_width="match_parent"
安卓:layout_height="370dp"
安卓:layout_gravity="center"
安卓:contentDescription="@string/show_logo"
安卓:scaleType="centerCrop" />
<GridView
安卓:id="@+id/hostGrid"
安卓:layout_width="match_parent"
安卓:layout_height="240dp"
安卓:layout_gravity="center"
安卓:columnWidth="100dp"
安卓:numColumns="auto_fit" />
<TextView
安卓:id="@+id/showDescription"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_margin="16dp"
安卓:textSize="20sp" />
<ListView
安卓:id="@+id/showListView"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content" />
</LinearLayout>
更新:截图
# 1 楼答案
通常,您希望ListView、RecyclerView等占据所有剩余空间,并且可能具有最小高度。既然你已经把自己的头发放在了一条直线上,这将很好地发挥作用:
如果在某些设备上发现它太小,则需要将LinearLayout放入某种滚动视图中,并在ListView上设置最小高度
要做到这一点,您需要使用NestedScrollView。实现这一目标的最佳方式如下:
希望这有帮助