1

I have created a card view as follows:

<android.support.v7.widget.CardView
android:id="@+id/card"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
card_view:cardBackgroundColor="#FF5722"
android:layout_width="fill_parent"
android:layout_height="135dp"
card_view:cardCornerRadius="5dp"
android:layout_marginTop="9dp"
android:layout_marginLeft="9dp"
android:layout_marginRight="9dp"
card_view:cardElevation="0.01dp"
android:layout_marginBottom="0dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true"
>
    <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"

    >


    <ImageView
        android:id="@+id/imgv"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:src="@drawable/android"
        />


    <RelativeLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="7">


           <TextView
               android:id="@+id/textview1"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>


           <TextView
               android:id="@+id/textview2"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="40dp"
               android:layout_marginTop="30dp"

               />  

       </RelativeLayout>


   </LinearLayout>

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

The above code however gives a padding to the image as shown below.I am running this in lollipop so I don't think there should be any problem.So why is this happening. I also tired adding card_view:cardPreventCornerOverlap="false" as said here.It still doesn't work.

Card View

Update

After changing the android:layout_height="wrap_content" instead of 135 dp it works perfectly.But I want to keep it as 135dp.How can I do that?

Community
  • 1
  • 1
xxx
  • 73
  • 1
  • 1
  • 5

2 Answers2

1

Try setting card_view:cardUseCompatPadding="false" as it causes some additional padding.

Joan S.
  • 150
  • 7
0

Try to remove the marginTop of the cardView. It adds extra spacing between cards.

ajantha
  • 1,585
  • 16
  • 23