Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android ListView仅显示第一项_Java_Android_Listview - Fatal编程技术网

Java Android ListView仅显示第一项

Java Android ListView仅显示第一项,java,android,listview,Java,Android,Listview,我有一个只显示一个项目的列表视图。如果我将ListView设置为一个设置的高度,我可以看到所有的项目都被加载到其中,但是wrap_内容只显示第一行 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertic

我有一个只显示一个项目的列表视图。如果我将ListView设置为一个设置的高度,我可以看到所有的项目都被加载到其中,但是wrap_内容只显示第一行

<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等占据所有剩余空间,并且可能具有最小高度。由于您的产品采用线性布局,这将很好地发挥作用:

<ListView
    android:id="@+id/showListView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

如果在某些设备上发现它太小,则需要将LinearLayout放入某种滚动视图中,并在ListView上设置最小高度

要做到这一点,您需要使用。实现这一目标的最佳方式如下:

<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>


希望这能有所帮助。

不要将
内容包装成
列表视图的高度。您可以在那里执行
match\u parent
,它只会占用
LinearLayout
中的剩余空间,因为这是最后一件事。谢谢,我尝试了您建议的代码,但没有成功。我以为你不应该在ScrollViewCheck中放置ListView,而ScrollViewCheck正是为了这个目的而制作的。我在这里编辑了我的答案,并举例说明了它的用法。谢谢你的尝试,我觉得它仍然不起作用。你能发布你所看到的东西的截图吗?添加到@DanielLaneDC上方