6

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.

4

1 回答 1

5

您可以为视图背景使用形状资源,可以是椭圆形:

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

或圆角矩形:

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

从你的问题中我不清楚你到底想要做什么。椭圆形将适合您的对象的宽度和高度。

当然,您可以通过自定义 Drawable 进行精确控制,实现自己的 draw() 方法并在画布上绘画。如果您正在寻找非常具体的东西,这可能是您最好的方法。

于 2013-10-01T14:55:21.383 回答