1

This is my card_view. I have mentioned card_view:cardElevation. But still shadow is not showing. I have searched many links. Everywhere they have mentioned to use card_view:cardElevation.

<android.support.v7.widget.CardView
            android:id="@+id/card_view"
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardBackgroundColor="@color/white"
            card_view:cardCornerRadius="4dp"
            card_view:cardElevation="5dp"
            card_view:cardUseCompatPadding="true"
            app:cardPreventCornerOverlap="false">
</android.support.v7.widget.CardView>

Can you tell what I am missing here?

2

2 Answers 2

4

Read https://developer.android.com/training/material/lists-cards.html

To create a card with a shadow, use the card_view:cardElevation attribute. CardView uses real elevation and dynamic shadows on Android 5.0 (API level 21) and above and falls back to a programmatic shadow implementation on earlier versions. For more information, see Maintaining Compatibility.

UPDATE

try adding margin to card if you want to see shadow

check https://developer.android.com/reference/android/support/v7/widget/CardView.html

6
  • I am using card_view:cardElevation. still shadow is not comming. and i am testing it on Lollipop Device also
    – ananya
    Jul 8, 2016 at 7:15
  • Isnt this helpful?@ananya Jul 11, 2016 at 6:25
  • No @Amit. I got the solution. Actually in my manifest file this one was false( android:hardwareAccelerated="false") I make it as ture and then it worked
    – ananya
    Jul 11, 2016 at 7:42
  • What is solution than @ananya Jul 11, 2016 at 7:43
  • check that comment @Amit. I edited the solution there
    – ananya
    Jul 11, 2016 at 7:46
0

Set the following attribute in your cardview

card_view:cardUseCompatPadding = "true"
card_view:cardElevation = "5dp"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.