有什么办法可以创建半圆作为形状吗?

Is there any way how to create half circle as shape?

我想为我的应用创建特殊视图。它是垂直虚线和上下两个半圆。有什么方法可以将其创建为单一形状的可绘制对象吗?我画了虚线,但是我画不出半圈。

应该是这样的。

垂直虚线:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="90" android:toDegrees="90">
    <shape
            android:shape="line">
        <stroke
                android:color="#777777"
                android:dashWidth="7dp"
                android:dashGap="5dp"
                android:width="2dp"/>
    </shape>
</rotate>

我发现有人试图画半个圆,但它很大。我只需要一个小圆圈。而且还不是圆

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners
            android:bottomLeftRadius="100000dp"
            android:topLeftRadius="0dp"
            android:bottomRightRadius="100000dp"
            android:topRightRadius="0dp" />

    <solid android:color="#777777" />
</shape>

您可以在 Canvas in android. And use the Path to define how it will be and Paint 对象的帮助下绘制整个视图以定义其颜色。

使用此行

drawable 下创建 half_circle.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#8C9AEE"/>
    <size
    android:width="120dp"
    android:height="60dp"/>
   <corners
    android:topLeftRadius="60dp"
    android:topRightRadius="60dp"/>
</shape>

设置half_circle.xml为布局背景

输出将如下所示: