Home » Android » android rounded corner textview with perfect round in the corner

android rounded corner textview with perfect round in the corner

Posted by: admin June 15, 2020 Leave a comment

Questions:

How to show a textview with rounded corner rectangle as shown in the orginal image
enter image description here

in the above (original) picture, the button 2’s left and right rounded corner are correctly shaped but in my code the left and right rounded corners are not shaped correctly

enter image description here

in the second picture I need to do more rounded as the 1st image. how can I do with following drawable?

drawable code (green_bg.xml)

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#19D8C8" />
    <corners android:radius="3dip" />
    <stroke
        android:width="10dp"
        android:color="#19D8C8" />
</shape>

activity_main.xml

.......
<TextView
    android:id="@+id/qmap_2"
    android:layout_width="35dp"
    android:layout_height="24dp"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:text="2"
    android:textStyle="bold"
    android:textColor="@color/no_color" />
    ......
How to&Answers:

create a file round.xml in drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#176d7a" />
    <corners android:radius="50dp" />
</shape>

now set the background of textview like

<TextView
    android:id="@+id/qmap_2"
    android:layout_width="35dp"
    android:layout_height="24dp"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:text="2"
    android:textStyle="bold"
    android:background="@drawable/round"
    android:textColor="@color/no_color" />

it should work

Answer:

Change the corner radius to a much higher value i.e 100dp

<corners android:radius="100dip" />

enter image description here