3

I am trying to create a shape with two rounded edges and two sharp edges. But I keep getting the following error:

The graphics preview in the layout editor may not be accurate:
Different corner sizes are not supported in Path.addRoundRect.

Here is the code

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

    <solid android:color="#888888" >
    </solid>

    <stroke
        android:width="2dp"
        android:color="#C4CDE0" >
    </stroke>

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

    <corners
        android:bottomLeftRadius="11dp"
        android:topLeftRadius="11dp" >
    </corners>

</shape>
Cote Mounyo
  • 13,817
  • 23
  • 66
  • 87
  • btw http://stackoverflow.com/questions/8399517/why-i-am-not-able-to-create-the-round-border-for-specific-corner does not work for me. – Cote Mounyo Jun 27 '13 at 21:28

5 Answers5

8

I am also facing the same problem. But for that I use layer-list. I post my answer here which may help you.
Please check output screen enter image description here

![<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#c1c1c1" />
            <solid android:color="#c1c1c1" />
            <corners android:radius="20dp"/>
        </shape>
   </item>

   <item android:right="20dp"
        >
      <shape 
        android:shape="rectangle">
            <stroke android:width="1dp" android:color="#c1c1c1" />
            <solid android:color="#c1c1c1" />
        </shape>
   </item>

</layer-list>][2]
Amol Wadekar
  • 886
  • 2
  • 14
  • 28
2

I was able to create exactly the effect you are looking for with the same shape that you have defined. The wording of the error is;

"The graphics preview in the layout editor may not be accurate:" This is only for the preview. Run the app and it should render as expected.

Edit

According to 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.

That seems to be the way that Google wants you to achieve the shape. I have ammended my code accordingly without issue.

CodeMonkey
  • 1,426
  • 1
  • 14
  • 32
1
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <corners
        android:topLeftRadius="10dp"
        android:bottomLeftRadius="10dp" />

    <solid android:color="#222224" />

</shape>
Atul O Holic
  • 6,692
  • 4
  • 39
  • 74
0

I just checked your code and used the same, for me it is working. Just cross check these things.

  1. Save shape.xml in \res\drawable folder.

  2. Set the background of Button in layout.

My lay-out file is

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

   <Button
    android:id="@+id/btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/shape"
    android:text="Click me" />

</LinearLayout>
0

use this online tool its very useful

http://angrytools.com/android/button/

your answer

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
      android:topLeftRadius="100dp"
      android:topRightRadius="100dp"
      android:bottomLeftRadius="0dp"
      android:bottomRightRadius="0dp"
 />
 <solid
      android:color="#2B9CB3"
 />
 <padding
      android:left="5dp"
      android:top="5dp"
      android:right="5dp"
      android:bottom="5dp"
 />
 <size
      android:width="270dp"
      android:height="60dp"
 />
 <stroke
      android:width="2dp"
      android:color="#FFFFFF"
  />
 </shape>

http://pastie.org/8952601

MilapTank
  • 9,988
  • 7
  • 38
  • 53