0

I want to create background for my main View where topLeft and bottomLeft corners will be rounded but right corners will be normal.

I've done this for several times for my RecyclerView layouts to make rounded corners for each View, but now it caused render error as I use elevation or translationZ to make soft shadow around the View.

Error: Invalid Region.Op - only INTERSECT and DIFFERENCE are allowed.

I found cause of this error. It seems like Android P has some issues with corner radius as it was stated here: java.lang.IllegalArgumentException: Invalid Region.Op - only INTERSECT and DIFFERENCE in Button background failure

Problem is that if I apply android:radius it will change radius for all 4 corners what I don't want. Is there any way how to make it functional?

Here is my background xml:

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="@android:color/background_light"/>
    <corners
            android:topLeftRadius="7dp"
            android:bottomLeftRadius="7dp"/>
martin1337
  • 2,384
  • 6
  • 38
  • 85
  • Maybe you can manually draw the shadow in using a layerlist in your background.xml, instead of depending on the elevation? – Zee Jan 03 '19 at 12:28

1 Answers1

1

One option is to manually draw the shadow into your background.xml. An advantage of this is that you then do not require the elevation. A disadvantage of this is that the shadow will be pretty sharp (like it wont have a nice gradient, but with some effort perhaps that would also be possible to draw in)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:top="2dp"
        android:right="2dp">

        <shape android:shape="rectangle">
            <solid android:color="#CABBBBBB" />
            <corners android:radius="2dp" />
        </shape>
    </item>

    <item
        android:bottom="2dp"
        android:left="2dp"
        android:right="0dp"
        android:top="0dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white" />
            <corners android:radius="2dp" />
        </shape>
    </item>
</layer-list>
Zee
  • 1,592
  • 12
  • 26