android-studio - Android 邊框陰影XML怎么實(shí)現(xiàn),或者說怎么實(shí)現(xiàn)
問題描述
Android 背景怎么實(shí)現(xiàn)內(nèi)部陰影邊框
或者這樣的陰影
問題解答
回答1:在drawable文件夾下建立一個(gè)shadow.xml文件,內(nèi)容如下:
<?xml version='1.0' encoding='utf-8'?><layer-list xmlns:android='http://schemas.android.com/apk/res/android'> <!-- 陰影部分 --> <!-- 個(gè)人覺得更形象的表達(dá):top代表下邊的陰影高度,left代表右邊的陰影寬度。其實(shí)也就是相對(duì)應(yīng)的offset,solid中的顏色是陰影的顏色,也可以設(shè)置角度等等 --> <itemandroid:left='2dp'android:top='2dp'><shape android:shape='rectangle'> <gradientandroid:angle='270'android:endColor='#0F000000'android:startColor='#0F000000'/> <cornersandroid:bottomLeftRadius='6dip'android:bottomRightRadius='6dip'android:topLeftRadius='6dip'android:topRightRadius='6dip'/></shape> </item> <!-- 背景部分 --> <!-- 形象的表達(dá):bottom代表背景部分在上邊緣超出陰影的高度,right代表背景部分在左邊超出陰影的寬度(相對(duì)應(yīng)的offset) --> <itemandroid:bottom='3dp'android:right='3dp'><shape android:shape='rectangle'> <gradientandroid:angle='270'android:endColor='#FFFFFF'android:startColor='#FFFFFF'/> <cornersandroid:bottomLeftRadius='6dip'android:bottomRightRadius='6dip'android:topLeftRadius='6dip'android:topRightRadius='6dip'/></shape> </item></layer-list>
在你的button里面,設(shè)置背景如下:
<Buttonandroid: android:layout_width='wrap_content'android:layout_height='wrap_content'android:background='@drawable/shadow'android:text='登錄'android:textSize='20dp'/>
具體效果可以自己調(diào)整shadow.xml里面的參數(shù)
