Android. Rounded rect

206 views Asked by At

How to create a rect with max rounded corners?

enter image description here

I tried:

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

    <size android:width="44dp"
        android:height="100dp"/>

    <solid android:color="#8c51ff"/>
    <corners android:radius="24dp"/>


</shape>
2

There are 2 answers

0
Siddharth_Vyas On

You can create a rectangle like this :

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

<!-- view background color -->
<solid
    android:color="@color/white" >
</solid>

<!-- If you want to add some padding -->
<padding
    android:left="5dp"
    android:top="5dp"
    android:right="5dp"
    android:bottom="5dp"    >
</padding>

<!-- Here is the corner radius -->
 <corners
    android:radius="6dp">
</corners> 

</shape>

Hope this answers your question.

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

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

    <solid android:color="@color/pure_white_color" />  
    <corners android:radius="25dp"/>    
    <stroke
        android:width="1dip"
        android:color="@color/text_view_border_color" />
  </shape>

Create a xml like "rounded.xml", and set background for the button as android:background="@drawable/rounded"