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.
Related videos on Youtube
Author by
Uma Achanta
Updated on January 02, 2022Comments
-
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 almost 8 yearscard_view:cardUseCompatPadding="true" should have done the magic.. Just as an option try harware accelerated in application tag in manifest and check.
-
W0rmH0le almost 8 yearsTry 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 almost 8 yearsgeorge-thomas: I tried that tag but no use
-
-
huzain07 about 6 yearsactually, 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 almost 6 years@Uma Achanta can you please help me to solve this stackoverflow.com/questions/50066346/…
-
Mehdi Karimi almost 6 yearsActually
card_view:cardUseCompatPadding="true"
fixed my problem, thanks -
Otziii about 4 yearsI used android:elevation="4dp" instead of card_view:cardElevation="4dp" (or app:cardElevation="4dp)
-
vidalbenjoe almost 4 yearsWorks for me after adding card_view:cardUseCompatPadding="true"