I'm trying to create a drawable layer-list that has a bitmap icon that
is interchangeable via "setLevel()" method. I cannot figure out how to
properly implement this. Any help would be much appreciated.

General App Setup:
I have a widget that loads a layer-list drawable into it's background.
I would like the bitmap (one of the items in the layer-list) in the
background to be able to switch between 9 different bitmaps (hopefully
using the setLevel method).

Expected result:
I should be able to call setLevel() on stage_icons to change the image
shown in the layer of the background.

Actual result:
Only image 0 shows by default, setLevel() method does not appear to
change anything, and it doesn't throw any errors.


/res/layout/main.xml  :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/widget_bg">
</RelativeLayout>


/res/drawable/widget_bg.xml  :

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android";
>
    <item
        android:top="20dp"
        android:left="30dp"
        android:right="5dp"
        android:bottom="0dp">

        <shape xmlns:android="http://schemas.android.com/apk/res/
android"
                android:shape="rectangle">
                        <gradient android:startColor="#FFa1285f"
                        android:endColor="#FF8b003f"
                        android:angle="270" />
                        <stroke android:width="2dp" android:color="#eeeb6aa4" />
                        <margin android:left="20dp" android:top="0dp"
                        android:right="0dp" android:bottom="0dp" />
                        <corners
                        android:bottomLeftRadius="0.1dp"
                        android:bottomRightRadius="20dp"
                        android:topLeftRadius="0.1dp"
                        android:topRightRadius="20dp"/>
                </shape>
    </item>
    <item android:id="@+id/stage_icons"
        android:drawable="@drawable/stage_icon_levels"
        android:top="2dp"
        android:left="2dp">

    </item>
</layer-list>


/res/drawable/stage_icon_levels.xml  :

<?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/
android">
  <item android:maxLevel="0" android:drawable="@drawable/
icon_stage_1" />
  <item android:maxLevel="1" android:drawable="@drawable/
icon_stage_2" />
 </level-list>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to