簡體   English   中英

Android ListView僅顯示第一項

[英]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僅顯示第一項,無法滾動

通常,您希望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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM