[英]Gradient background doesn't work in some Devices
我正在使用漸變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);
}
從shadow_background.xml中刪除此塊(第一個項塊)。
<item>
<shape android:shape="rectangle" >
</shape>
</item>
為了檢查shadow_background,我做了一個像這樣的布局,它似乎工作(甚至在xml編輯器中的API10)。
(如果您離開第一個項目塊,LinearLayout將填充黑色。)
FrameLayout
(Background = @color/light_green)
LinearLayout
(Background = @drawable/shadow_background)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.