Niko
Niko

Reputation: 8153

Android support CardView issues with shadows

I am using android.support.v7.widget.CardView library and facing some problems.

Here I have simply stacked 3 CardViews using some margin. Running it on Android L the top shadows for top 2 cards are not seen/drawn.Can't see top shadows

Here is API level 16 drawing the cards.

enter image description here

Is it possible the get the top shadow always drawn?

Thanks.

EDIT: xml code

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="16dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="@dimen/card_view_corner_radius"
    app:cardUseCompatPadding="true" />

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="16dp"
    android:layout_marginLeft="4dp"
    android:layout_marginRight="4dp"
    android:layout_marginTop="4dp"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="@dimen/card_view_corner_radius"
    app:cardUseCompatPadding="true" />

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp"
    app:cardBackgroundColor="@color/white"
    app:cardCornerRadius="@dimen/card_view_corner_radius"
    app:cardPreventCornerOverlap="true"
    app:cardUseCompatPadding="true">

Upvotes: 2

Views: 1560

Answers (2)

Niko
Niko

Reputation: 8153

Based on my study, I believe that GPU drawing updates along with elevation causes this. Since the cards are on same elevation level with same background the platform blends them. Thats why older version draws some border because it doesn't support elevation.

My fix was to add 0dp elevation for bottom card, then 1dp for middle and the top card keeps it's default elevation which is 2dp. Now there is slight border visible.

Upvotes: 2

Mohamed
Mohamed

Reputation: 656

Try this:

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp"
    card_view:cardBackgroundColor="@color/white"
    card_view:cardCornerRadius="@dimen/card_view_corner_radius"
    card_view:cardElevation="4dp" />

Maybe cardElevation do it.

Upvotes: 0

Related Questions