96

I want to make a shape with with left-top rounded corner and left-bottom rounded corner:

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#555555"/>    

    <stroke android:width="3dp"
            android:color="#555555"
            />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp"
             /> 

    <corners android:bottomRightRadius="0dp" android:bottomLeftRadius="2dp" 
     android:topLeftRadius="2dp" android:topRightRadius="0dp"/> 
</shape>

But the shape above didn't give me what I want. It gives me a rectangle without any rounded corners.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
user256239
  • 17,717
  • 26
  • 77
  • 89

8 Answers8

72

It looks like a bug http://code.google.com/p/android/issues/detail?id=939.

Finally I have to write something like this:

 <stroke android:width="3dp"
         android:color="#555555"
         />

 <padding android:left="1dp"
          android:top="1dp"
          android:right="1dp"
          android:bottom="1dp"
          /> 

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

I have to specify android:bottomRightRadius="2dp" for left-bottom rounded corner (another bug here).

user256239
  • 17,717
  • 26
  • 77
  • 89
  • 1
    Yes, I can confirm your last statement/bug that left/right is switched there. I experienced the same in my app as well. (sdk 2.1). Did you file a bug report on b.android.com already for it or is it reported there already? – Mathias Conradt Jun 17 '10 at 01:30
  • 3
    I just filed a bug, http://code.google.com/p/android/issues/detail?id=9161. The sad thing is, after they fix the bug, I have to change my code again :( – user256239 Jun 17 '10 at 17:30
58

While this question has been answered already (it's a bug that causes bottomLeftRadius and bottomRightRadius to be reversed), the bug has been fixed in android 3.1 (api level 12 - tested on the emulator).

So to make sure your drawables look correct on all platforms, you should put "corrected" versions of the drawables (i.e. where bottom left/right radii are actually correct in the xml) in the res/drawable-v12 folder of your app. This way all devices using an android version >= 12 will use the correct drawable files, while devices using older versions of android will use the "workaround" drawables that are located in the res/drawables folder.

Geoff
  • 2,892
  • 1
  • 22
  • 14
  • 4
    Another option is to use a default `values/dimens.xml` file that contains the inverted bottom_left and bottom_right values, and a new `values-v12/dimens.xml` file that has the *correct* values. That way you can keep just a single version of the drawable XML file, and only the dimen value is swapped based on the API version. – Joe Aug 26 '14 at 18:47
36

From the documentation:

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.

E.g. you have to set an android:radius="<bigger than 1dp>" to be able to do what you want:

<corners 
    android:radius="2dp"
    android:bottomRightRadius="0dp" 
    android:topRightRadius="0dp"/> 
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Entreco
  • 12,738
  • 8
  • 75
  • 95
15

You can also use extremely small numbers for your radius'.

<corners 
  android:bottomRightRadius="0.1dp" android:bottomLeftRadius="2dp" 
 android:topLeftRadius="2dp" android:topRightRadius="0.1dp" />
Moncader
  • 3,388
  • 3
  • 22
  • 28
12

for others there are a solution for any API level , you can place a item on top of each other example :

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

<!-- my firt item with 4 corners radius(8dp)
 -->
    <item>
        <shape>
            <solid
                android:angle="270.0"
                android:color="#3D689A" />

            <corners android:topLeftRadius="8dp" />
        </shape>
    </item>
<!-- my second item is on top right for a fake corner radius(0dp)
 -->
    <item
        android:bottom="30dp"
        android:left="50dp">
        <shape>
            <solid android:color="#5C83AF" />
        </shape>
    </item>
<!-- my third item is on bottom left for a fake corner radius(0dp)
 -->
    <item
        android:right="50dp"
        android:top="30dp">
        <shape>
            <solid android:color="#5C83AF" />
        </shape>
    </item>

</layer-list>

the result with light color to show you the three items :

enter image description here

the final result :

enter image description here

Best regards.

Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
James
  • 311
  • 3
  • 4
8

This bug is filed here. This is a bug of android devices having API level less than 12. You've to put correct versions of your layouts in drawable-v12 folder which will be used for API level 12 or higher. And an erroneous version(corners switched/reversed) of the same layout will be put in the default drawable folder which will be used by the devices having API level less than 12.

For example: I had to design a button with rounded corner at bottom-right.

In 'drawable' folder - button.xml: I had to make bottom-left corner rounded.

<shape>
    <corners android:bottomLeftRadius="15dp"/>
</shape>

In 'drawable-v12' folder - button.xml: Correct version of the layout was placed here to be used for API level 12 or higher.

<shape>
    <corners android:bottomLeftRadius="15dp"/>
</shape>
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
8

try this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/upkia"/>
<corners android:radius="10dp"
    android:topRightRadius="0dp"
    android:bottomRightRadius="0dp" />
</shape>
saigopi.me
  • 14,011
  • 2
  • 83
  • 54
1

This works for me

  <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
    <corners
        android:bottomLeftRadius="0dp"
        android:radius="@dimen/dimen_5dp"
        android:topLeftRadius="0dp" />
</shape>

Achived this

Aalishan Ansari
  • 641
  • 6
  • 8