Android curved rectangular shape

I want to create a rectangular shape in XML, it needs a curved shape. Is this possible with XML markup or programmatically?

The code I have is:

<?xml version="1.0" encoding="UTF-8" ?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <corners android:topLeftRadius="45dp" android:topRightRadius="45dp" android:bottomLeftRadius="45dp" android:bottomRightRadius="45dp" /> <solid android:color="#4F4F4F" /> <stroke android:width="3dp" android:color="#878787" /> </shape> 

Can someone help me?

enter image description here

My idea is as follows:

http://i.stack.imgur.com/RD7I0.png

The rectangle must be transformed by a curve.

+7
android android-drawable
source share
1 answer

You can use the form resource for the background of your view, or oval:

 <shape android:shape="oval"> <stroke android:width="1dp" android:color="#FF000000" /> </shape> 

or rounded rectangle:

 <shape android:shape="rectangle"> <stroke android:width="1dp" android:color="#FF000000" /> <corners android:radius="20dp" /> </shape> 

it is not clear to me, from your question, what you want to do for sure. The oval will match your objects in width and height.

Of course, you can have precise control through custom Drawable using your own draw () method and drawing on canvas. This is probably your best approach if you are looking for something very specific.

+6
source share

All Articles