The problem is that CardViews are natively supported on api-21 and up, and on KitKat and earlier they are "faked" by the support library.
What I've done in the past with success is to use separate layout files, and just manually pixel-push them until it looks right.
For example, in res/layout
, you have this xml:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="0dip"
android:layout_marginLeft="0dip"
android:layout_marginTop="1dip"
android:layout_marginBottom="1dip"
cardview:cardBackgroundColor="@color/even_light_gray"
android:foreground="@drawable/card_foreground"
cardview:cardCornerRadius="1dp" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:paddingTop="4dp" >
<!-- .......... -->
</LinearLayout>
</android.support.v7.widget.CardView>
Then, in res/layout-21
, you have this layout with different margin and padding values:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_card"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginRight="1dip"
android:layout_marginLeft="1dip"
android:layout_marginTop="4dip"
android:layout_marginBottom="4dip"
cardview:cardBackgroundColor="@color/even_light_gray"
android:foreground="@drawable/card_foreground"
cardview:cardCornerRadius="1dp" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingTop="4dp" >
<!-- .......... -->
</LinearLayout>
</android.support.v7.widget.CardView>