CardView elevation not showing in lollipop and higher versions

23,551

Solution 1

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">`

Solution 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.

Share:
23,551

Related videos on Youtube

Uma Achanta
Author by

Uma Achanta

Updated on January 02, 2022

Comments

  • Uma Achanta
    Uma Achanta over 2 years

    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.

    • George Thomas
      George Thomas almost 8 years
      card_view:cardUseCompatPadding="true" should have done the magic.. Just as an option try harware accelerated in application tag in manifest and check.
    • W0rmH0le
      W0rmH0le almost 8 years
      Try to remove: card_view:cardElevation="2sp" or change it to "2dp". Cardview has an default elevation already... you don't need to set it...
    • Uma Achanta
      Uma Achanta almost 8 years
      george-thomas: I tried that tag but no use
  • huzain07
    huzain07 about 6 years
    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
  • Nikson
    Nikson almost 6 years
    @Uma Achanta can you please help me to solve this stackoverflow.com/questions/50066346/…
  • Mehdi Karimi
    Mehdi Karimi almost 6 years
    Actually card_view:cardUseCompatPadding="true" fixed my problem, thanks
  • Otziii
    Otziii about 4 years
    I used android:elevation="4dp" instead of card_view:cardElevation="4dp" (or app:cardElevation="4dp)
  • vidalbenjoe
    vidalbenjoe almost 4 years
    Works for me after adding card_view:cardUseCompatPadding="true"