프로그래밍 언어/Java

[Android java] background custom 그라데이션 그림자 주는 법

happy_life 2021. 11. 17. 11:29

Background를 custom 할 때 그라데이션식으로 그림자를 주는 방법

투명도를 주는 것을 활용하여 디자인 하였습니다.

색상코드 앞 두자리에 투명도를 줄 수 있습니다. 

 

1.drawable 에 디자인 xml만들기

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

    <!-- Drop Shadow Stack -->
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AF6F2FA" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AF5EDFF" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AEDE0FD" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AE9D7FF" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AE3CCFF" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1ADABDFD" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AD3B3FB" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1AD0AEFB" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1ACEA8FF" />
        </shape>
    </item>
    <item>
        <shape>
            <padding
                android:bottom="2.5dp"
                android:left="2.5dp"
                android:right="2.5dp"
                android:top="2.5dp" />
            <corners android:radius="12dp"/>
            <solid android:color="#1ACCA4FF" />
        </shape>
    </item>


    <!-- Background -->
    <item>
        <shape>

            <corners android:radius="12dp"/>
            <solid android:color="@android:color/white" />
        </shape>
    </item>

</layer-list>

 

 

2. Activity_main.xml 코드

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:gravity="center">


    <LinearLayout
        android:layout_gravity="center"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:background="@drawable/layoutdesign"
        >


    </LinearLayout>


</LinearLayout>