Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a rectangle with rounded corners using XML?

Here is markup snippet for drawing rectangle with four rounded corners:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

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

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

    <corners android:radius="2dp"></corners>

</shape>

But if I want to round the corners on one side only (two corners), how can I do it?

Thanks.

like image 662
Mark Korzhov Avatar asked Aug 05 '15 09:08

Mark Korzhov


2 Answers

Create a draw-able resource:-

<?xml version="1.0" encoding="utf-8"?>
<!--  res/drawable/rounded_edittext.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#FFFFFF"/>
<corners
 android:bottomRightRadius="15dp"
 android:bottomLeftRadius="15dp"
 android:topLeftRadius="15dp"
 android:topRightRadius="15dp"/>
</shape>

Set above in background of any view.

like image 115
Adarsh Yadav Avatar answered Oct 06 '22 20:10

Adarsh Yadav


   <corners
    android:bottomLeftRadius="2dp"
    android:bottomRightRadius="2dp"
    android:topLeftRadius="2dp"
    android:topRightRadius="2dp" />
like image 28
RamBabu Pudari Avatar answered Oct 06 '22 19:10

RamBabu Pudari