Reputation: 15740
My goal is to have a list item with a ripple effect on click, and an elevation. I know that in order to have elevation, currently it is required that you also have a non-transparent color for the background of the view which is making the elevation's shadow.
This is the background I'm using for my list item:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/ripple_color">
<item>
<shape android:shape="rectangle">
<solid android:color="@android:color/white"/>
<stroke android:color="@color/border_color"
android:width="0.25dp"/>
</shape>
</item>
</ripple>
As you can see I'm setting the solid value to white, and when the view is drawn it has a white background. To make sure this value was being used, I changed it to red and the view changed to a red background, so it's not like the solid
element is being ignored.
I also made a test of switching this background out for just plain white, and that gave a correct elevation shadow, so I know the problem isn't with something else.
What do I need to add to this in order for my elevation to appear?
Upvotes: 3
Views: 716
Reputation: 232
Is your stroke-color (@color/border_color) semitransparent? I just discovered that my missing elevation-shadows came back after I changed my stroke to a color that doesn't have transparency.
Elevation won't display for shapes with transparency, and apparently , even if you solid is not semi-transparent, it won't work if your stroke is semi-transparent.
I don't know if a shape's elevation will always fail if there's any type of element with transparency in it, but it might be the case.
Upvotes: 3
Reputation: 8473
If you have no problem with making CardView
as parent viewgroup of the row of RecyclerView
, You can use card_view:cardElevation
attribute for the elevation.
But it requires xmlns schema :
xmlns:card_view="http://schemas.android.com/apk/res-auto"
you must include it in order to make use of that attribute. :)
Upvotes: -1