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?
My idea is as followed:
The rectangle has to be transformed with a curve.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With