[英]Android ListView only shows first item
我有一个ListView仅显示一项。 如果将ListView设置为设置的高度,则可以看到所有项目都已加载到其中,但是wrap_content仅显示第一行。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.fmsirvent.ParallaxEverywhere.PEWImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="370dp"
android:layout_gravity="center"
android:contentDescription="@string/show_logo"
android:scaleType="centerCrop" />
<GridView
android:id="@+id/hostGrid"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_gravity="center"
android:columnWidth="100dp"
android:numColumns="auto_fit" />
<TextView
android:id="@+id/showDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="20sp" />
<ListView
android:id="@+id/showListView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
更新:屏幕截图
通常,您希望ListView,RecyclerView等占据所有剩余空间,并且可能具有最小高度。 由于您已将其放置在LinearLayout中,因此可以很好地工作:
<ListView
android:id="@+id/showListView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
如果在某些设备上发现它太小,则需要将LinearLayout放入某种ScrollView中,并在ListView上设置最小高度。
为此,您将需要使用NestedScrollView 。 实现此目标的最佳方法如下所示:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.fmsirvent.ParallaxEverywhere.PEWImageView
android:id="@+id/logo"
android:layout_width="match_parent"
android:layout_height="370dp"
android:layout_gravity="center"
android:contentDescription="@string/show_logo"
android:scaleType="centerCrop" />
<GridView
android:id="@+id/hostGrid"
android:layout_width="match_parent"
android:layout_height="240dp"
android:layout_gravity="center"
android:columnWidth="100dp"
android:numColumns="auto_fit" />
<TextView
android:id="@+id/showDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:textSize="20sp" />
<ListView
android:id="@+id/showListView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.