我想在 XML 中创建一个矩形,它需要一个弯曲的形状。 这可以通过 XML 标记或以编程方式实现吗?
我现在的代码:
<?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>
有人可以帮帮我吗?
我的思路是这样的:
矩形必须用曲线进行变换。
最佳答案
您可以为 View 背景使用形状资源,可以是椭圆形:
<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() 方法并在 Canvas 上绘画。如果您正在寻找非常具体的东西,这可能是您的最佳方法。
关于android - 弧形矩形机器人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19118474/