Why i am not able to create the round border for specific corner?
Asked Answered
L

4

18

In My android xml layout i am applying the border by using the borderframe.xml as a background.

borderframe.xml file is looks like below:

    <?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dip" 
        android:color="#ffffff"/>
    <solid 
        android:color="#95865F"/>
    <corners 
        android:radius="10px"/>

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

Now, While there is a android:radius="10px" then it is works but while i am going to give round shape to specific corner only then it not works. There is no any erro message in log cat but i found error in eclipse like:

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

Even if there is no padding in that xml file then also i am not able to see any border.

Now, what should i have to do for it ? and whats the sollution of it if i want to create the rounded border for only topLeftcorner and bottomLeftCorner. ? Thanks.

Letourneau answered 6/12, 2011 at 11:57 Comment(0)
C
10

You'll have to do that, assuming you only want a rounded top left corner:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="20sp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <gradient
      android:startColor="@color/logo_blue"
      android:endColor="@color/blue"
      android:angle="0"/>
</shape>

Explanation: 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. [source]

As a consequence, you need to define your drawable as:

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dip" 
        android:color="#ffffff"/>
    <solid 
        android:color="#95865F"/>
    <corners 
       android:radius="10px"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp" />

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

Update

From The Shape Drawable Resource Android Documentation:

android:radius Dimension. The radius for all corners, as a dimension value or dimension resource. This is overridden for each corner by the following attributes.

overridden is the keyword for your problem…

Complainant answered 6/12, 2011 at 12:0 Comment(12)
Ok Thanks. But if there is no padding define in shape then i am not able to see the border . . why ?Letourneau
If there is no padding in to that shape then i am not able to see the corner why ??Letourneau
please help me in this matter.Letourneau
have you tried to increase the padding values to a big value to see what happen (for example 10dp)?Complainant
I think the padding is for the inner content but i must verifyComplainant
Yes I have try many. But without padding i am not able to create the rounded corner. And if i give padding the my view become bad. Is there any other alternate ??Letourneau
Actualy i have image at the leftTop corner and bottomleft corner of the layout. I think thats why i am not able to create the rounded shape there ? Is it right ?Letourneau
For sure ! Now you an try to clip your image using a ClipDrawable but I don't know if you can use rounded corners with this one. Anyway, please update your question…It's too bad for the readers to read all those comments.Complainant
I don't understand why there are two code snippets in this answer. Are you rounding the corners in the drawable and in something else?Amour
The first one is an example extracted from one of my project at that time. The second one is an adaptation to the original question's snippet. The corners are indeed rounded in the drawable, see the corners element. For the second snippet, we apply the 10 px radius to all the corners expected for topRightRadius and bottomRightRadius which are specifically set to 0dp. Is this clear?Complainant
The corner radius should be 20dp instead of spPtero
@Nepster The first snippet is an arbitrary fragment taken from a project of mine. I used sp there because I need the corner to depend on the font size (the shape is for a text header…) Now, maybe you know better…Complainant
P
17

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 image 1

<?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>
Palladium answered 1/4, 2014 at 6:57 Comment(0)
C
10

You'll have to do that, assuming you only want a rounded top left corner:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
  <corners
      android:radius="20sp"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp"
      android:bottomLeftRadius="0dp" />
  <gradient
      android:startColor="@color/logo_blue"
      android:endColor="@color/blue"
      android:angle="0"/>
</shape>

Explanation: 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. [source]

As a consequence, you need to define your drawable as:

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dip" 
        android:color="#ffffff"/>
    <solid 
        android:color="#95865F"/>
    <corners 
       android:radius="10px"
      android:topRightRadius="0dp"
      android:bottomRightRadius="0dp" />

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

Update

From The Shape Drawable Resource Android Documentation:

android:radius Dimension. The radius for all corners, as a dimension value or dimension resource. This is overridden for each corner by the following attributes.

overridden is the keyword for your problem…

Complainant answered 6/12, 2011 at 12:0 Comment(12)
Ok Thanks. But if there is no padding define in shape then i am not able to see the border . . why ?Letourneau
If there is no padding in to that shape then i am not able to see the corner why ??Letourneau
please help me in this matter.Letourneau
have you tried to increase the padding values to a big value to see what happen (for example 10dp)?Complainant
I think the padding is for the inner content but i must verifyComplainant
Yes I have try many. But without padding i am not able to create the rounded corner. And if i give padding the my view become bad. Is there any other alternate ??Letourneau
Actualy i have image at the leftTop corner and bottomleft corner of the layout. I think thats why i am not able to create the rounded shape there ? Is it right ?Letourneau
For sure ! Now you an try to clip your image using a ClipDrawable but I don't know if you can use rounded corners with this one. Anyway, please update your question…It's too bad for the readers to read all those comments.Complainant
I don't understand why there are two code snippets in this answer. Are you rounding the corners in the drawable and in something else?Amour
The first one is an example extracted from one of my project at that time. The second one is an adaptation to the original question's snippet. The corners are indeed rounded in the drawable, see the corners element. For the second snippet, we apply the 10 px radius to all the corners expected for topRightRadius and bottomRightRadius which are specifically set to 0dp. Is this clear?Complainant
The corner radius should be 20dp instead of spPtero
@Nepster The first snippet is an arbitrary fragment taken from a project of mine. I used sp there because I need the corner to depend on the font size (the shape is for a text header…) Now, maybe you know better…Complainant
E
6

I'm using SDK tools 19, platform-tools 11 and running the app in Android 4.0.3. Using the following XML 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="#dd000000"/>
    <padding 
        android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp" />
    <corners
        android:bottomLeftRadius="25dp"
        android:bottomRightRadius="25dp"
        android:topLeftRadius="0dp"
        android:topRightRadius="0dp" />
</shape>

The Eclipse warning is about not being able to show the preview. In het app it shows up correct.

Eer answered 14/6, 2012 at 15:38 Comment(1)
Aha. It still happens with Android Studio as of now.Phylum
C
-1

I got the solution on one of the forums. I solved it by commenting each corner & adding to the xml in drawable. I have retained commented code below only for understanding.

XML Code-

   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
        <solid android:color="#fd2149" />
        <stroke android:width="1dip" android:color="#ffd102"/>
      <!--  <corners
            android:bottomLeftRadius="8dp"
            android:bottomRightRadius="8dp"
            android:topLeftRadius="8dp"
            android:topRightRadius="8dp" />
        -->
        <corners android:radius="8dp" />
    </shape>

---Edited- The above code is my back.xml in drawable folder and if required you can add padding to the same back.xml. For those who are new developers, the back.xml is referenced from your layout file as follows

  <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textSize="20sp"
    android:scrollbars="vertical"
    android:background="@drawable/back">

Hope this helps.

Crop answered 28/5, 2016 at 12:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.