2

I have made and app with CardView, but my cardview is going into one card.

My Code:

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

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

I think the only issue is with the gap between your CardViews. You must not be having CompatPadding true in CardView thats why it looks like the data is clubbed into one CardView try making it true. Use following code it should work :

<?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>
Manishika
  • 5,478
  • 2
  • 22
  • 28
  • What do you mean by returning action bar! Your question had no action bar point. What exactly is the issue with the action bar. I answered your question for cardview issue and I guess that is working now. Right? – Manishika Jul 12 '16 at 06:37
  • 1
    You can take help from here http://www.vogella.com/tutorials/AndroidActionBar/article.html . If my answer is correct for your cardview problem then mark it as answer. Thanks – Manishika Jul 12 '16 at 10:18