changing layer-list drawables

Problems with Canvas, OpenGL, etc...

changing layer-list drawables

Postby HibridO » Mon May 23, 2011 2:38 pm

Hi,

I'm new to android programming. I'm trying to change a item inside a layerlist when the user press a button. The problem is that when the button is clicked, the drawable disapears. If I finish the intend and start it again, the drawable apears updated. Can someone see what I'm doing wrong?

The XML code for the layerlist is:

Code: Select all
<layer-list android:id="@+id/avatar_image" xmlns:android="http://schemas.android.com/apk/res/android" >
    <item
        android:id="@+id/bg_layer"
        android:drawable="@drawable/background01" />

    <item
        android:id="@+id/skin_layer"
        android:drawable="@drawable/skin01" />

    <item
        android:id="@+id/face_layer"
        android:drawable="@drawable/face01" />


(...)

In the XML Code for the window I have:

Code: Select all
<ImageView
            android:id="@+id/avatar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/avatar_image"
            android:layout_centerHorizontal="true"
            />


So for the OnClickListener I have:

Code: Select all
layerView = (ImageView) findViewById(R.id.avatar);
      layerList = (LayerDrawable) layerView.getDrawable();

Code: Select all
bgButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            layerList.setDrawableByLayerId(R.id.bg_layer, res.getDrawable(R.drawable.background02));
            layerList.invalidateSelf();

        }
    });


Without invalidateSelf() the behaviour is the same. Can someone help me out?
HibridO
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 23, 2011 2:34 pm

Top

Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest