worked
worked

Reputation: 5880

Android + CardView adding margins to non-L versions?

Same layout, but rendering differently between L and all other versions.

4.1.2

enter image description here

5.0

enter image description here

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="0dp"
    android:background="#FFFFFFFF"
    android:elevation="40dp"
    android:padding="0dp"
    android:translationZ="0dp"
    app:cardBackgroundColor="#FFFFFFFF"
    app:cardCornerRadius="2dp"
    app:cardElevation="40dp"
    app:cardPreventCornerOverlap="true"
    app:cardUseCompatPadding="true"
    app:contentPadding="10dp" >

    <TextView
        android:layout_width="wrap_content"
        android:gravity="center_horizontal"
        android:layout_gravity="center_vertical"
        android:layout_height="wrap_content"
        android:background="#FFFFFFFF"
        android:text="TEXTVIEW" />
</android.support.v7.widget.CardView>

Upvotes: 5

Views: 2788

Answers (1)

sbaar
sbaar

Reputation: 1425

This is working as intended. The shadows pre-L are "simulated". From the documentation "CardView uses elevation property on L for shadows and falls back to a custom shadow implementation on older platforms." There are other compatibility concerns there you should read about. Particularly, make sure to set useCompatPadding to true for consistency.

Upvotes: 2

Related Questions