2

我已經制作並使用CardView的應用程序,但是我的卡片視圖將進入一張卡片。Cardview全部進入一張卡片

我的代碼:

recyclerview_activity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:padding="16dp" 
    > 

    <android.support.v7.widget.RecyclerView 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:id="@+id/rv" 
     > 

    </android.support.v7.widget.RecyclerView> 


</LinearLayout> 

I get something like this

+1

請這裏一併複製item.xml你與你的代碼 – Manishika

+0

@manishika得到什麼的截圖,添加 –

+0

這不是一個論壇。您通過接受答案來「解決」帖子。 –

回答

1

我認爲唯一的問題是與你的CardViews之間的差距。你不能在CardView上有CompatPadding這就是爲什麼它看起來像數據clubbed到一個CardView嘗試使它成真。 使用下面的代碼它應該工作:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/cv" 
    card_view:cardCornerRadius="5dp" 
    card_view:cardUseCompatPadding="true" 
    android:foreground="?android:attr/selectableItemBackground" 
> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="16dp" 
    > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/person_photo" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="16dp" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/person_name" 
     android:layout_toRightOf="@+id/person_photo" 
     android:layout_alignParentTop="true" 
     android:textSize="30sp" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/person_age" 
     android:layout_toRightOf="@+id/person_photo" 
     android:layout_below="@+id/person_name" 
     /> 

</RelativeLayout> 

</android.support.v7.widget.CardView> 
+0

返回行動欄是什麼意思!你的問題沒有行動欄點。操作欄的問題究竟是什麼?我回答你的問題cardview問題,我想現在工作。對? – Manishika

+1

你可以從這裏獲取幫助http://www.vogella.com/tutorials/AndroidActionBar/article.html。如果我的回答對於你的cardview問題是正確的,那麼將其標記爲答案。謝謝 – Manishika

相關問題