Android – gradient backgrounds don’t work on some devices

I'm using gradient drawable for image internal shadow. It works for some devices (check-in simulator) but doesn't work in some devices. First of all, I think it will depend on API level devices, but today I check the same thing. It doesn't work on tablets with API level "16" (i.e. jelly beans)

Gradient code (for internal shadows on all four edges):

<?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>

My layout code:

 <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>

And the uisng gradient in my code is:

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);
}

resolvent:

From shadow_ Delete this block (the first item block) from background.xml

<item>
    <shape android:shape="rectangle" >
    </shape>
</item>

To check shadow_ Background, I made a layout like this, which seems to work (even api10 in the XML Editor). (if you leave the first project block, LinearLayout will be filled with black.)

FrameLayout
(Background = @color/light_green)
    LinearLayout
    (Background = @drawable/shadow_background)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>