CardView Not Showing Shadow In Android L
Answer :
After going through the docs again, I finally found the solution.
Just add card_view:cardUseCompatPadding="true"
to your CardView
and shadows will appear on Lollipop devices.
What happens is, the content area in a CardView
take different sizes on pre-lollipop and lollipop devices. So in lollipop devices the shadow is actually covered by the card so its not visible. By adding this attribute the content area remains the same across all devices and the shadow becomes visible.
My xml code is like :
<android.support.v7.widget.CardView android:id="@+id/media_card_view" android:layout_width="match_parent" android:layout_height="130dp" card_view:cardBackgroundColor="@android:color/white" card_view:cardElevation="2dp" card_view:cardUseCompatPadding="true" > ... </android.support.v7.widget.CardView>
Do not forget that to draw shadow you must use hardwareAccelerated
drawing
hardwareAccelerated = true
hardwareAccelerated = false
See Android Hardware Acceleration for details
use app:cardUseCompatPadding="true"
inside your cardview. For Example
<android.support.v7.widget.CardView android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginRight="@dimen/cardviewMarginRight" app:cardBackgroundColor="@color/menudetailsbgcolor" app:cardCornerRadius="@dimen/cardCornerRadius" app:cardUseCompatPadding="true" app:elevation="0dp"> </android.support.v7.widget.CardView>
Comments
Post a Comment