2017-02-25 11 views
1

私はListViewが1つのアイテムしか表示していません。 ListViewを高さに設定すると、すべてのアイテムがロードされていることがわかりますが、wrap_contentは最初の行のみを表示しています。Androidリストには最初のアイテムしか表示されません

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

アップデート:スクリーンショット

The listView only displays the first item and cannot be scrolled

+1

'ListView'の高さに' wrap_content'をしないでください。 'match_parent'をそこに置くことができ、' LinearLayout'の残りの部分を占めるようになります。最後のものですから。 –

答えて

2

一般的に、あなたはリストビューなど、RecyclerViewは、残りのスペースのすべてを取ると、おそらく最小の高さを持っていると思います。あなたがのLinearLayoutにあなたを持っているので、これはうまく動作します:

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

あなたはそれが一部のデバイスでは小さすぎる見つけた場合、あなたはScrollViewのいくつかの並べ替えにのLinearLayoutを入れて、上の最小の高さを設定する必要がありますリストビュー。

これを行うには、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> 

+0

ありがとう、私はあなたが示唆したコードを試しましたが、うまくいきませんでした。私は、ScrollViewの中にListViewを置くことになっていないと思った。 – robbiestells

+0

[NestedScrollView](https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html)をチェックアウトしたこの正確な目的。私はここでその使用法の例を使って答えを編集しました。 – DanielLaneDC

+0

試していただきありがとうございます、まだ私のために動作していないようです – robbiestells

関連する問題