Search code examples
androidandroid-drawableandroid-shape

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


I want to create special view for my app. It is vertical dotted line and two half circles on a top and bottom. Is there any way how to create this as single shape drawable? I made dotted line, but I cant make half circle.

It should looks like this.

enter image description here

Dotted vertical line:

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

I have found as someone tried to make half circle, but its big. I need only small circle. And it is not even circle.

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

Solution

  • Create half_circle.xml file under drawable with this line

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

    set half_circle.xml as background of layout

    output will be look like :

    enter image description here