Damini Mehra Damini Mehra - 2 months ago 60
Android Question

How to add shadow around circular imageview

I want to add shadow around circular imageView.
Here is my code.
I want to make like this image
image

This is my .xml file
check this image.
screenshot1

activity_main.xml

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

<RelativeLayout
android:id="@+id/layoutTop"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#355482" >
</RelativeLayout>

<RelativeLayout
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/layoutTop"
android:background="@drawable/loading" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="113dp"
android:text="Profile"
android:textColor="#355482"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>

<ImageView
android:id="@+id/overlapImage"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="132dp"
android:adjustViewBounds="true"
android:background="@drawable/round_image"
android:src="@drawable/ic_launcher" />



this is round_image.xml:

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">

<solid android:color="#ffffff" />
<corners android:radius="2dp"/>

<size
android:height="80dp"
android:width="80dp" />

<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp" />

</shape>


i try some code for shadow effect but its not working. sorry for my bad English.
Thank in advance

Answer

Hope this will help you:)

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item>
        <shape android:shape="oval">
              <solid android:color="@color/gray"/>
                <!--shadow Color-->
        </shape>
    </item>

    <item
        android:left="0dp"
        android:right="0dp"
        android:top="0dp"
        android:bottom="3dp">
        <shape android:shape="oval">
             <solid android:color="@color/lightgrey"/>//Background Color
        </shape>
    </item>
</layer-list>

Change the background Color and Shadow color as you want..