26

I was using cardview, but the problem is elevation not showing in lollipop and higher versions. please suggest me.Here is my code.

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/verify_card"
        android:layout_weight="1"
        card_view:cardBackgroundColor="@android:color/white"
        card_view:cardElevation="2sp"
        card_view:cardUseCompatPadding="true"
        />

Thanks in advance.

Uma Achanta
  • 3,669
  • 4
  • 22
  • 49

2 Answers2

81

this worked for me.

xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"

total code is:

<android.support.v7.widget.CardView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_margin="8dp"
    android:id="@+id/card_griditem"
    android:layout_height="match_parent"
    card_view:cardUseCompatPadding="true"
    card_view:cardElevation="4dp"
    card_view:cardCornerRadius="3dp">`
Serg Chernata
  • 12,280
  • 6
  • 32
  • 50
Uma Achanta
  • 3,669
  • 4
  • 22
  • 49
  • 13
    actually, u just need add layout_margin on carview. and dont set it to 0, cuz it prevent u from showing the shadow of cardview – huzain07 Mar 12 '18 at 02:35
  • @Uma Achanta can you please help me to solve this https://stackoverflow.com/questions/50066346/cardview-gridlayout-with-recyclerview-is-not-fit-for-all-screen-sizes-in-andro – Nikson Apr 27 '18 at 16:13
  • 21
    Actually `card_view:cardUseCompatPadding="true"` fixed my problem, thanks – Mehdi Karimi May 23 '18 at 14:19
  • I used android:elevation="4dp" instead of card_view:cardElevation="4dp" (or app:cardElevation="4dp) – Otziii Apr 01 '20 at 08:46
  • Works for me after adding card_view:cardUseCompatPadding="true" – vidalbenjoe May 23 '20 at 04:19
2

Make sure you have set android:hardwareAccelerated="false" as true in Manifest. By setting it to false your application will not able to use GPU and can't make some 2D designs.

Bharat Lalwani
  • 1,277
  • 15
  • 17