zzy
zzy

Reputation: 1793

Background didn't be draw in case of different corner?

I want create a view with different corners , the shape's xml is following:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

<solid android:color="#01A2EA" />

<corners
    android:bottomLeftRadius="30dp"
    android:bottomRightRadius="30dp"
    android:radius="30dp"
    android:topLeftRadius="30dp"
    android:topRightRadius="30dp" />

</shape>

It performs good with blue background, but after I changed two of four corner radius like:

<corners
    android:bottomLeftRadius="30dp"
    android:bottomRightRadius="30dp"
    android:radius="30dp"
    android:topLeftRadius="0dp"
    android:topRightRadius="0dp" />

It lost its backgound color and I can see nothing.

The API document says:

Note: Every corner must (initially) be provided a corner radius greater than 1, or else no corners are rounded. If you want specific corners to not be rounded, a work-around is to use android:radius to set a default corner radius greater than 1, but then override each and every corner with the values you really want, providing zero ("0dp") where you don't want rounded corners.

But it seems dosen't work correctly with background ?

Upvotes: 1

Views: 73

Answers (2)

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

Yes you are right there is a bug, But you can resolve it like this.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">

    <solid android:color="#01A2EA" />

    <corners
        android:bottomRightRadius="30dp"
        android:bottomLeftRadius="30dp"
        android:topRightRadius="0.1dp"
        android:topLeftRadius="0.1dp"/>
</shape>

NOTE :

This may not reflect at design time. So please run the code to see effect.

Upvotes: 1

Ammar
Ammar

Reputation: 1821

Use following instead.

<corners
    android:bottomLeftRadius="30dp"
    android:bottomRightRadius="30dp" />

Upvotes: 1

Related Questions