背景
在安卓開發(fā)中,有時UI設(shè)計師需要給某個東西加個陰影。安卓里自帶了Cardview,能實現(xiàn)下面這樣的效果。

image
問題
Cardview提供了陰影效果,但是存在兩個問題:
1、無法修改陰影顏色
2、無法修改投影方向(Cardview的投影是從上往下投影的)
解決方案
網(wǎng)上有人做了其他開源庫來改變投影顏色和投影方向,但是效果都不太好,甚是苦惱。
后來在同事提醒下,才發(fā)現(xiàn),其實根本就不復(fù)雜,用個點九圖就可以了。
讓美工做個帶陰影的邊框圖,然后自己在AndroidStudio里做成點九圖,拿這個做背景圖就ok了。

image
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_gravity="center"
android:layout_margin="20dp"
android:background="@drawable/test"
android:gravity="center"
android:text="望洞庭\n湖光秋月兩相和,潭面無風(fēng)鏡未磨。\n遙望洞庭山水翠,白銀盤里一青螺。" />
附錄
在線制作帶陰影.9圖工具:
https://gitee.com/lblbc/shadow4android
http://inloop.github.io/shadow4android/
