• 안드로이드스튜디오 레이아웃에 그림자 넣기

    2020. 9. 21.

    by. 민영답게

    버튼이나 이미지에 그림자를 줄때는 elevation을 이용하면 됐었는데

    레이아웃에 그림자를 넣은 예제들이 많이 없어서 찾고 적용하는데 시간이 조금 걸렸다..

     

    결론적으로는,

    xml을 만들고 해당 레이아웃의 아래에 새로 view나 layout을 추가하여 background로 지정해주면 된다.

     

    하단에 그림자를 넣는 xml 코드

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:startColor="#DFDDDD"
            android:endColor="#F7F9FC"
            android:angle="270"
            >
        </gradient>
    </shape>

     

    상단에 그림자를 넣는 xml 코드

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:startColor="#F7F9FC"
            android:endColor="#E3E2E2"
            android:angle="270"
            >
        </gradient>
    </shape>
    

    * 색은 자기가 원하는 색으로 수정하여 사용하면 된다.

     

    그림자를 넣을 레이아웃 아래에 추가할 코드

    <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="10dp"
          android:background="@drawable/layout_shadow">
    </LinearLayout>

     

    'Android' 카테고리의 다른 글

    안드로이드스튜디오 파일(창)이 안열릴때  (0) 2020.09.03

    댓글