Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 684
worked Avatar asked Oct 31 '22 15:10

worked


1 Answers

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.

like image 181
sbaar Avatar answered Nov 11 '22 11:11

sbaar