2

my android version is 4.2 and i'm trying to remove white border and space from that but my solution as card_view:cardPreventCornerOverlap="false" from xmlns:app="http://schemas.android.com/apk/res-auto" namespace doesnt work correctly

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:elevation="0dp"
    card_view:cardPreventCornerOverlap="false">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/market_item_background">

        <ImageView
            android:id="@+id/market_thumbnail"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:scaleType="centerCrop"/>

    </RelativeLayout>

this is part of my application which i used CardView

enter image description here

mahdi pishguy
  • 994
  • 1
  • 14
  • 43
  • did you try following attribute together ? card_view:cardPreventCornerOverlap="false" card_view:cardUseCompatPadding="true" – Amir Jul 24 '16 at 08:18
  • @Amir this option as `cardUseCompatPadding` it cause of i get extra padding for cardview – mahdi pishguy Jul 24 '16 at 08:22
  • cardUseCompatPadding is **if we set this property to true then margin works same on all versions** use -2 margin and guess your problem will be fixed. – Amir Jul 24 '16 at 08:27
  • @Amir No amir, your soluton doesnt work correctly on all of versions and thats not good practice – mahdi pishguy Jul 24 '16 at 08:31

5 Answers5

5

Try setting

setCardElevation(0);
setMaxCardElevation(0);

and

card_view:cardPreventCornerOverlap="false"

Source: Cardview - white border around card

Community
  • 1
  • 1
NiCk.JaY
  • 141
  • 1
  • 8
1

After much research only thing work for me with pre lollipop devices

with using both

xmlns:app="http://schemas.android.com/apk/res-auto"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"

in CardView,

this is a old question but might help somebody

UdayaLakmal
  • 4,035
  • 4
  • 29
  • 40
0

Replace android:layout_margin="10dp" for android:layout_padding="10dp"

John Sardinha
  • 3,566
  • 6
  • 25
  • 55
0

I think that setting setMaxCardElevation(0) will be enough in that case. No need in setCardElevation(0) or card_view:cardPreventCornerOverlap="false"

userVadim
  • 80
  • 2
  • 7
0

I set card background color to transparent and it makes the white border disappear

app:cardBackgroundColor="@android:color/transparent"
Buckstabue
  • 283
  • 1
  • 13