我正在使用渐变drawable用于
Image内部阴影,它适用于某些设备(检入模拟器)但在某些设备中不起作用.首先我认为它将取决于api级别的设备但是今天我检查同样的事情在具有api级别“16”(即果冻豆)的平板电脑上,它也不起作用.
渐变代码(适用于所有四个边的内部阴影):
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item> <shape android:shape="rectangle" > </shape> </item> <item android:bottom="114dip" android:top="0dip"> <shape android:shape="rectangle" > <gradient android:angle="270" android:endColor="#00000000" android:startColor="#40000000" /> </shape> </item> <item android:bottom="0dip" android:top="114dip"> <shape android:shape="rectangle" > <gradient android:angle="90" android:endColor="#00000000" android:startColor="#40000000" /> </shape> </item> <item android:left="0dip" android:right="114dip"> <shape android:shape="rectangle" > <gradient android:angle="360" android:endColor="#00000000" android:startColor="#40000000" /> </shape> </item> <item android:left="114dip" android:right="0dip"> <shape android:shape="rectangle" > <gradient android:angle="180" android:endColor="#00000000" android:startColor="#40000000" /> </shape> </item> </layer-list>
我的布局代码:
<FrameLayout android:id="@+id/about" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_weight="1" android:background="@color/light_green" > <ImageView android:id="@+id/home_icon_placeholder" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/home_icon_placeholder" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:drawablePadding="5dp" android:drawabletop="@drawable/about_icon" android:gravity="center" android:text="@string/about_champions_club_btn_txt" android:textColor="@android:color/white" android:textSize="12sp" android:textStyle="bold" /> </FrameLayout>
和我的代码中的uisng渐变为:
int sdk = android.os.Build.VERSION.SDK_INT; if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) { placeHolderImageViewAbout.setBackgroundColor(getResources().getColor(R.color.transparent)); } else { //shadow background is above mention gradient placeHolderImageViewAbout.setBackgroundResource(R.drawable.shadow_background); }