1

I have a RecyclerView with items on it. When I run it on Lollipop devices everything is great. But when I run it on pre-lollipop devices there is a white border around every view.

White small border around pre-lollipop recyclerview

Edit: I didn't post code before cause I thought was some kind of bug.

Rec.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"      
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#333333"
tools:context=".MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/my_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/text"
    android:scrollbars="vertical" />

</RelativeLayout>

main_card_view.xml

<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="4dp"
android:layout_margin="5dp">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#222222"
    >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/image"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:scaleType="centerCrop"
        android:src="@drawable/ic_launcher" />
    <RelativeLayout
        android:layout_width="320dp"
        android:layout_height="240dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignBottom="@+id/image"
        android:background="#bb000000"
        android:id="@+id/rel_color">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Μπύρα"
            android:textColor="#fcfcfc"
            android:textSize="40sp"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowColor="#000000"
            android:id="@+id/text"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"
            android:gravity="center" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="8$"
            android:id="@+id/textView3"
            android:textColor="#fcfcfc"
            android:layout_alignParentBottom="true"
            android:textSize="28sp"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowColor="#000000"
            android:layout_alignBottom="@+id/text"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_margin="10dp" />
    </RelativeLayout>

</RelativeLayout>
</android.support.v7.widget.CardView>
marduc812
  • 1,177
  • 17
  • 26

1 Answers1

1

The problem is because of CardView.

Set setPreventCornerOverlap(false) on your CardView.

And extend ImageView to make a custom class like RoundedCornerImageView and use it inside CardView insted of ImageView.

Answer on this question will be helpful.

Note : You can make your own custom class i.e RoundedCornerIm... or use a lib like in the linked SO question i.e here on github.

Edit :

Okay i think you are a little confused so,

1) RecyclerView is the container layout for your list/grid. i.e

android:id="@+id/my_recycler_view"

as i can c in pictures, you must be having a GridLayoutManager attached to RecyclerView. Likewise to put data in your RecyclerView you must be attaching an adapter as well.

Again if you have an adapter i.e a class that extends Adapter class(maybe RecyclerView.Adapter). Now the adapter class must be given a layout to inflate i.e your main_card_view.xml inside RecyclerView in a grid style beacuse of GridLayoutManager.

So every item in your RecyclerView is a main_card_view.xml

Now in your Class that extends adapter class (i.e attached to the recycler view) there will be CardView -- You have to make changes there.

Community
  • 1
  • 1
Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41
  • So I have to make RecyclerView to CardView to make it look both the same? There is no way to do it on RecyclerView? – marduc812 Apr 15 '15 at 16:21
  • No! You don't have to change recycler view. Recycler view and card view are different. You have a card views inside recycler view. I.e android.support.v7.widget.CardView (I.e in your main_card_view.xml) you have to make both changes in main_card_view.xml ! Ask me if you still don't follow up.. – Kushal Sharma Apr 15 '15 at 16:30
  • Sorry but still I don't get it. CardView is the layout that helps with the View. My main layout is RecyclerView. I can refer to recyclerview since it's in my Rec.xml that is my main layout. How can I refer to CardView when there is only a RecyclerView in my layout? – marduc812 Apr 15 '15 at 17:34
  • Thank you for your answer you were right although I couldn't do it again. I used an other way I added what you said in XML. card_view:cardPreventCornerOverlap="false" and worked perfect. Seems I have to try a little bit more I'm kind of confused! Thank you a lot once again! – marduc812 Apr 15 '15 at 17:50
  • Glad i could help, actualy its the same thing. I was telling you how to do it in java files and you solved it by changing the xml. You will understand in time :D have a nice day :) – Kushal Sharma Apr 15 '15 at 17:52
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75319/discussion-between-user3347882-and-rogerthatcode). – marduc812 Apr 15 '15 at 17:52