android - 弧形矩形机器人

标签 android android-drawable

我想在 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>

有人可以帮帮我吗?

enter image description here

我的思路是这样的:

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

矩形必须用曲线进行变换。

最佳答案

您可以为 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/

相关文章:

android - 无法访问 jarfile SignApk

android - 使用可绘制对象 xml 文件和图像

Java Android Studio : Convert image from camera to Binary

android - 减少 BitmapDrawable 大小

android - 在android中有没有办法比较两个音频文件之间的相似性?

android - 为什么某些设备不支持我们的 Android 应用程序

java - 在Android中获取Bitmap的所有像素

android - API 16 中添加了 xxhdpi 密度,如果我只提供 xxhdpi 资源,<16 会怎样?

Android RecyclerView : Change layout file LIST to GRID onOptionItemSelected

Android - 如何使用 Espresso 单击抽屉导航上的项目?