如何在安卓中绘制弧线

5

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

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"
     />

3个回答

3

试试这段代码:

 <?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>

Output:
enter image description here
不满意吗?为什么不使用 这个 在画布上创建它,或者使用 这个 将SVG转换为XML代码呢?

0

尝试使用这个包含笔画的代码

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#90000000" />
            <size
                android:width="120dp"
                android:height="60dp" />
            <corners
                android:topLeftRadius="60dp"
                android:topRightRadius="60dp" />
        </shape>
    </item>
    <item
        android:bottom="0dp"
        android:left="1dp"
        android:right="1dp"
        android:top="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#90DF1E1E" />
            <size
                android:width="120dp"
                android:height="60dp" />
            <corners
                android:topLeftRadius="60dp"
                android:topRightRadius="60dp" />
        </shape>
    </item>
</layer-list>

enter image description here


-1

你可以尝试:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="oval"
       android:useLevel="false" >
   <solid android:color="#006AC5" />
   <size
    android:height="50dp"
    android:width="50dp" />
</shape>

这是一个例子:

enter image description here

希望它能解决你的问题!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接