增加陰影效果,讓控件或者布局看起來有立體的效果,總的來說有兩種解決方案。
1,直接使用屬性: android/45708.html">android/104884.html">android:elevation="4dp"這樣一句代碼,就實現了效果,elevation表示海拔,就是布局的z軸的高度,調整高度,可以選擇陰影的輕重。
<TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:elevation="4dp" android:background="@drawable/home_waitcourse_yellow_shape" android:textColor="@color/foorYellow" android:text="報道"/>
2,這種方式就需要寫點代碼了,但是也不多,是通過寫一個xml來實現的。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 陰影部分 --> <!-- 個人覺得更形象的表達:top代表下邊的陰影高度,left代表右邊的陰影寬度。其實也就是相對應的offset,solid中的顏色是陰影的顏色,也可以設置角度等等 --> <item android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp"> <shape android:shape="rectangle" > <gradient android:angle="270" android:endColor="#0F000000" android:startColor="#0F000000" /> <corners android:bottomLeftRadius="6dip" android:bottomRightRadius="6dip" android:topLeftRadius="6dip" android:topRightRadius="6dip" /> </shape> </item> <!-- 背景部分 --> <!-- 形象的表達:bottom代表背景部分在上邊緣超出陰影的高度,right代表背景部分在左邊超出陰影的寬度(相對應的offset) --> <item android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="5dp"> <shape android:shape="rectangle" > <gradient android:angle="270" android:endColor="#FFFFFF" android:startColor="#FFFFFF" /> <corners android:bottomLeftRadius="6dip" android:bottomRightRadius="6dip" android:topLeftRadius="6dip" android:topRightRadius="6dip" /> </shape> </item> </layer-list>
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答