How to create a transparent semicircle?

I want to create this effect. TextView with transparent semicircle as backgound. enter image description here I tried to add a selection as a background.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" >
    <solid android:color="#00000000" />
</shape>

also i have tried this https://stackoverflow.com/a/2126646/2129 , but it does not work for me. Can anybody help me?

+4
source share
1 answer

You cannot create a semicircle from xml. but you can achieve what you are looking for using a circle with the appropriate margin and retreat.

Create a fixed size circle as follows:

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

Now use it as the background of your TextView as follows:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFF00">

    <ImageView
        android:contentDescription="@string/app_name"
        android:id="@+id/img"
        android:layout_width="fill_parent"
        android:layout_height="200dip"
        android:layout_alignParentTop="true"
        android:background="#006AC5" />

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/img"
        android:layout_marginTop="-35dip"
        android:paddingTop="10dip"
        android:background="@drawable/circle"
        android:layout_centerHorizontal="true"
        android:text="@string/one"
        android:gravity="center"/>

</RelativeLayout>

, -25dip ( ) TextView, , 10dip (& 10dip padding, ), , .

ImageView, , , ImageView TextView, z- index, TextView . , , :)

+4

All Articles