Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - drawable with rounded corners at the top only

I had this drawable to have a rounded rectangle as a background:

<shape xmlns:android="http://schemas.android.com/apk/res/android">     <solid android:color="@color/white" />     <stroke android:width="1dp" android:color="@color/light_gray" />     <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />     <corners android:radius="6dp" /> </shape> 

This is working fine, as expected.

Now, I want to change this to only round the top corners, so I change it to this:

<shape xmlns:android="http://schemas.android.com/apk/res/android">     <solid android:color="@color/white" />     <stroke android:width="1dp" android:color="@color/light_gray" />     <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp" />     <corners android:topLeftRadius="6dp" android:topRightRadius="6dp"              android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/> </shape> 

But now none of the corners are rounded and I get a plain rectangle. What am I missing here?

like image 432
Aleks G Avatar asked Jan 19 '12 17:01

Aleks G


People also ask

How do I curve the edges in Android Studio?

Here's What To Do:Create a rounded shape drawable and set it as your view's background: android:background="@drawable/round_outline" Clip to outline in code: setClipToOutline(true)

What is Android App rounded?

Android 12 introduces Rounded Corner API that enables you to get the properties of a screen's rounded corners, such as its center and its radius. As you can see in the image above, with this API you app can be made aware of the screen's rounded corner and avoid truncating the UI elements.


1 Answers

Try giving these values:

 <corners android:topLeftRadius="6dp" android:topRightRadius="6dp"          android:bottomLeftRadius="0.1dp" android:bottomRightRadius="0.1dp"/> 

Note that I have changed 0dp to 0.1dp.

EDIT: See Aleks G comment below for a cleaner version

like image 119
aqs Avatar answered Oct 30 '22 03:10

aqs