Saturday, November 9, 2019

Android custom shape circle

Today I'm going to show you an Androd shape circle, the simplest example you can use right now.
Step 1. create a layout: activity_main.xml
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    tools:context=".MainActivity"
    android:background="#9C1AB1"
    >
  <ImageView
      android:layout_width="300dp"
      android:background="@drawable/custom_circle_shape"
      android:layout_centerInParent="true"
      android:layout_height="300dp" />
</RelativeLayout>
Step 2. Custom shape circle in drawable :  custom_circle_shape.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#eae1ff" />
            <corners android:radius="2dp"/>
            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="oval">
            <solid android:color="#50ffffff" />
            <corners android:radius="2dp"/>


            <padding
                android:bottom="0dp"
                android:left="0dp"
                android:right="0dp"
                android:top="0dp" />
        </shape>
    </item>
</selector> 
Result Android shape circle below:

Android custom shape circle

No comments:

Post a Comment