4

I'm using a gradient drawable for a Image inner-shadow, It works fine for some devices(check in emulator) but doesn't work in some.First i thought it will depend on api level of device but today i check same thing on Tablet having api level "16" (i.e jelly bean) and it doesn't work on it either.

Gradient code(For inner shadows for all four sides):

<?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 uisng gradient in my code as :

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);
}
Manish
  • 1,259
  • 3
  • 11
  • 20
  • Have you checked hardware acceleration enabled? [Android 3.0 Hardware Acceleration](http://android-developers.blogspot.jp/2011/03/android-30-hardware-acceleration.html) [How to enable Hardware Acceleration on ICS, but disable in Gingerbread?](http://stackoverflow.com/questions/11109595/how-to-enable-hardware-acceleration-on-ics-but-disable-in-gingerbread) Look at shalafi's answer. – Toris Jul 11 '14 at 05:26
  • @Toris - thanks for reply , but not working with this also. – Manish Jul 11 '14 at 06:00

1 Answers1

4

Remove this block (first item block) from your shadow_background.xml.

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

To check shadow_background, I made a layout like this and it seems to work (even on API10 in xml editor).
(If you leave the first item block, LinearLayout will be filled with black color.)

FrameLayout
(Background = @color/light_green)
    LinearLayout
    (Background = @drawable/shadow_background)
Toris
  • 2,348
  • 13
  • 16
  • yeah!! it did the trick.. but will you please tell me why this shape attribute not working in some devices. – Manish Jul 11 '14 at 07:45
  • 3
    @Manish In some devices, shape's solid color default is black (not transparent). [Shape Drawables on Samsung devices default to black background](http://stackoverflow.com/questions/21333286/shape-drawables-on-samsung-devices-default-to-black-background) – Toris Jul 11 '14 at 18:46