Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a shape with left-top round rounded corner and left-bottom rounded corner?

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.

like image 662
user256239 Avatar asked Jun 16 '10 18:06

user256239


People also ask

What is a rectangle with rounded corners called?

A rounded rectangle is the shape obtained by taking the convex hull of four equal circles of radius and placing their centers at the four corners of a rectangle with side lengths and . A filled rounded rectangle with (or. ) is called a stadium. The rounded rectangle has perimeter.


2 Answers

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).

like image 55
user256239 Avatar answered Sep 21 '22 11:09

user256239


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.

like image 29
Geoff Avatar answered Sep 20 '22 11:09

Geoff