android - 如何在android中制作圆弧

标签 android xml

我只是想知道如何制作这个半圆

enter image description here

但是我的输出是这样的

enter image description here

这是我的 xml:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:topLeftRadius="20dp"
android:topRightRadius="20dp"
 />
<stroke
    android:width="2dip"
    android:color="@android:color/darker_gray"
    />
<padding
    android:left="4dp"
    android:right="4dp"
     />

最佳答案

试试这个代码:

 <?xml version="1.0" encoding="utf-8"?>
    <shape
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <solid android:color="#900021df"/>
        <size
        android:width="120dp"
        android:height="60dp"/>
       <corners
        android:topLeftRadius="60dp"
        android:topRightRadius="60dp"/>
    </shape>

在drawable文件夹下创建一个semicircle.xml。
将以上代码添加到您的XML中。
请让我知道它是否有效...

输出看起来像

enter image description here

编辑:

对上面的代码稍加修改即可。

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

   <size
       android:width="120dp"
       android:height="60dp"/>
   <corners
       android:topLeftRadius="60dp"
       android:topRightRadius="60dp"/>
   <stroke
      android:color="#919191"
      android:width="1dp"
      />

</shape>


输出:
enter image description here

不满意?为什么不使用 this 在 Canvas 上创建它或使用this将 SVG 转换为 XML 代码?

关于android - 如何在android中制作圆弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47066435/

相关文章:

xml - 忽略子节点的 XPath 表达式

android - 获得插图的正确方法

android - 创建phonegap android项目时出错 cscript 不是可识别的内部或外部命令

java - Android 上的回调函数

Android AndEngine RegisterUpdateHandler 可变时间

java - 为什么 sax 解析比 dom 解析快? stax 是如何运作的?

android - 当我尝试在Android程序中放入背景时出现错误

android - android中配置网络安全xml报错

c# - 美化多个 XSD 文件

android - 通知中的 Intent 选择器