Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curved rectangle shape android

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

the code i have now:

<?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 out?

enter image description here

My idea is as followed:

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

The rectangle has to be transformed with a curve.

like image 626
Ivan Ivanov Avatar asked Oct 01 '13 14:10

Ivan Ivanov


1 Answers

You can use a shape resource for your view background, either an oval:

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

or a rectangle with rounded corners:

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

it's not clear to me from your question what you're looking to do exactly. The oval will fit to your objects width and height.

Of course you can have precise control via a custom Drawable, implementing your own draw() method and painting on the canvas. This is likely your best approach if you're looking for something very specific.

like image 129
CSmith Avatar answered Oct 28 '22 01:10

CSmith