0

In my app I am displaying in a recyclerview the table ranking of the Premier League.All data are received through a webservice(Volley in this case). Everything works great except that I have a repeated relative layout that holds text values Pos,Team,GP,Pts as shown.

My Screenshot

Now you can see the problem. In every row I have those Pos,...,Pts text. And this is my xml code.

   android:id="@+id/recLayout"
 >

 <!--
uncomment the below xml code for card view.
also delete the background attribute in the RelativeLayout
-->

<android.support.v7.widget.CardView
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_below="@+id/relativeLayout1"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    android:background="#666686"
    card_view:cardCornerRadius="4dp"

    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true">




    <RelativeLayout

        android:background="#dedee1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >


        <!-- <ImageView -->
        <com.android.volley.toolbox.NetworkImageView
            android:id="@+id/thumbnail"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:padding="10dp"
            android:layout_gravity="center_horizontal"
            android:scaleType="fitXY"
            android:src="@drawable/default_placeholder"
            android:layout_marginLeft="23dp"
            android:layout_marginStart="23dp"
            android:layout_alignParentTop="true"
            android:layout_toRightOf="@+id/position"
            android:layout_toEndOf="@+id/position" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="1"
            android:id="@+id/position"
            android:layout_marginLeft="12dp"
            android:layout_marginStart="12dp"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="31"
            android:layout_marginTop="37dp"
            android:id="@+id/played"
            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:layout_alignTop="@+id/position"
            android:layout_toRightOf="@+id/thumbnail"
            android:layout_toEndOf="@+id/thumbnail" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="61"
            android:id="@+id/points"
            android:layout_marginLeft="25dp"
            android:layout_marginStart="25dp"
            android:layout_alignTop="@+id/played"
            android:layout_toRightOf="@+id/played"
            android:layout_toEndOf="@+id/played" />


        <!-- un-comment for card view -->

    </RelativeLayout>

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


<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Pos"
        android:id="@+id/textView3"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="14dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Team"
        android:id="@+id/textView4"
        android:layout_marginLeft="44dp"
        android:layout_marginStart="44dp"
        android:layout_alignTop="@+id/textView3"
        android:layout_toRightOf="@+id/textView3"
        android:layout_toEndOf="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="GP"
        android:id="@+id/textView5"
        android:layout_marginLeft="49dp"
        android:layout_marginStart="49dp"
        android:layout_alignTop="@+id/textView4"
        android:layout_toRightOf="@+id/textView4"
        android:layout_toEndOf="@+id/textView4" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="Pts"
        android:id="@+id/textView6"
        android:layout_marginLeft="22dp"
        android:layout_marginStart="22dp"
        android:layout_alignTop="@+id/textView5"
        android:layout_toRightOf="@+id/textView5"
        android:layout_toEndOf="@+id/textView5" />
    -->
</RelativeLayout>

Any ideas what could be wrong in my xml file?

Thanks

Theo
  • 3,099
  • 12
  • 53
  • 94

2 Answers2

1

You're inflating that xml for each recyclerview item, correct? The undesired layout is also included below your cardview. You would need to remove that relativelayout and include it in your activity layout, not the recylerview item layout.

craya
  • 613
  • 6
  • 18
1

Try to add header for recylerview

Check below link

Is there an addHeaderView equivalent for RecyclerView?

Community
  • 1
  • 1