Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set view shadow only on sides for view with elevation

Tags:

I have a RecyclerView with various view types. Each view has own background with top, bottom or no rounded corners. Each use the same view elevation. This is one of the backgrounds in XML

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:color="@color/card_background_pressed"
    tools:targetApi="lollipop">
    <item>
        <shape>
            <size
                android:width="1dp"
                android:height="1dp" />
            <solid android:color="@color/card_background_normal" />
        </shape>
    </item>
</ripple>

When views are laid out next to each other without any margin it looks like having the same background. This is my way for creating dynamic card background. In other words I can create single looking card from multiple items in RecyclerView

Problem

As you can see below, when 2 views are laid out next to each other their shadows are overlapping each other in the corners, even when corner background radius is 0.

So does anyone know how to fix it? I care only for API 21+ so need to worry about older versions support. Thanks in advance!

enter image description here