How To Properly Set Elevation Value To Recyclerview?
Solution 1:
I found the answer after a little bit of searching from here. The problem was the transparent background. Elevation works with only non-transparent backgrounds on views. To fix it we should set android:outlineProvider="bounds"
on the view and android:clipToPadding="false"
on the view's parent.
Hope it helps someone.
Solution 2:
For Lollipop and you can use the android:elevation property but below lollipop versions you have to give custom shadow so refer the below code for shadow
card_background.xml
<?xml version="1.0" encoding="utf-8"?><layer-listxmlns:android="http://schemas.android.com/apk/res/android"><item><shapeandroid:shape="rectangle"><solidandroid:color="#CABBBBBB"/><cornersandroid:radius="2dp" /></shape></item><itemandroid:left="0dp"android:right="0dp"android:top="0dp"android:bottom="2dp"><shapeandroid:shape="rectangle"><solidandroid:color="@android:color/white"/><cornersandroid:radius="2dp" /></shape></item></layer-list>
Give this file as a background to your recyclerview inflater file it will work fine.
Solution 3:
Just set below three property in your recyclerview
android:outlineProvider="bounds"android:background="@null"android:elevation="2dp"
Solution 4:
The android:elevation does only apply shadows on devices which are running Lollipop or later. If you want to suppot older devices, you have to create a shadow yourself.
Post a Comment for "How To Properly Set Elevation Value To Recyclerview?"