2016-08-25 17 views
0

リストからいくつかのCardViewを表示するRecyclerViewを実装しましたが、問題が表示されたときにカード間に余裕があり、スペースはCardViewと同じスペースです高さが高く、各カードの底部にのみあります。カード間のRecyclerView、CardView、 "dead"スペース

これは私のコードです:

CardView:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:cardview="http://schemas.android.com/apk/res-auto" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:gravity="center_horizontal" 
android:padding="5dp"> 
<android.support.v7.widget.CardView 
    android:layout_width="fill_parent" 
    android:layout_height="245dp" 
    android:layout_gravity="center_horizontal" 
    cardview:cardElevation="4dp" 
    cardview:cardCornerRadius="5dp" 
    android:layout_marginBottom="0dp"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="240dp" 
     android:orientation="vertical" 
     android:padding="8dp"> 
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:id="@+id/ivProduct" 
      android:scaleType="centerCrop" /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#333333" 
      android:text="Photo Title" 
      android:id="@+id/txtTipo" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="5dp" /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#333333" 
      android:text="Photo Title" 
      android:id="@+id/txtdescripcion" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="5dp" /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 

RecyclerView:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView" 
    android:scrollbars="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
</LinearLayout> 

1

[2]

[[2] [2]!]

enter image description here

+0

何が起きているのかを示す画像を追加します。おそらく、あなたは 'android:layout_height'と比べて十分な高さを使用していない可能性が高いので、2つの間に奇妙な間隔があります。あなたは代わりにコンテンツをラップすることができます。 –

+0

イメージを置くだけで、どこにコンテンツをラップする必要がありますか? – elunap

+0

あなたは 'RecyclerView'で親全体を塗りつぶしているので、フルスクリーンに1つのアイテムしか表示されないように見えます。代わりに 'wrap_content'を使うべきです。実際の「RecyclerView」ではこれが変わるはずだと思う。あなたのカードのあなたの親のレイアウトでは、代わりに 'match_parent'を使うべきです。 –

答えて

1

あなたのLinearLayoutはfill_parent高さがあるので、高さがちょうどwrap_contentのために変更、画面の高さを想定しています。

<?xml version="1.0" encoding="utf-8"?> 
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:cardview="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"   <!--change in this line--> 
    android:gravity="center_horizontal" 
    android:padding="5dp"> 
<android.support.v7.widget.CardView 
    android:layout_width="fill_parent" 
    android:layout_height="245dp" 
    android:layout_gravity="center_horizontal" 
    cardview:cardElevation="4dp" 
    cardview:cardCornerRadius="5dp" 
    android:layout_marginBottom="0dp"> 
    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="240dp" 
     android:orientation="vertical" 
     android:padding="8dp"> 
     <ImageView 
      android:layout_width="fill_parent" 
      android:layout_height="100dp" 
      android:id="@+id/ivProduct" 
      android:scaleType="centerCrop" /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#333333" 
      android:text="Photo Title" 
      android:id="@+id/txtTipo" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="5dp" /> 
     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="#333333" 
      android:text="Photo Title" 
      android:id="@+id/txtdescripcion" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginLeft="5dp" /> 
    </LinearLayout> 
</android.support.v7.widget.CardView> 
</LinearLayout> 
+0

これはそれです!どうもありがとう!! :) – elunap

0

私はあなたが私たちのサンプルで直接見てみることをお勧めします:

https://github.com/xamarin/monodroid-samples/tree/master/android5.0/RecyclerViewer/RecyclerViewer

ありますが、これに近づくことができる多くの方法がありますが、全体的な問題は、あなたがRecyclerView高さの内側に子供を与えているということです画面全体を埋めるのに十分です。したがって、あなたは彼らに十分な身長を与えてwrap_contentにするべきです。 RecyclerView内部

https://github.com/xamarin/monodroid-samples/blob/master/android5.0/RecyclerViewer/RecyclerViewer/Resources/layout/PhotoCardView.axml#L5

https://github.com/xamarin/monodroid-samples/blob/master/android5.0/RecyclerViewer/RecyclerViewer/Resources/layout/PhotoCardView.axml#L8

関連する問題