I tried to combine animation-list with state list in my application. I
found an answer here:

http://stackoverflow.com/questions/5299219/button-states-with-background-as-animationdrawable-in-android

My button has an animation and a 'pressed' state. The onClick listener
simply exits the activity (not the whole application). Unfortunately
when I go back to the activity - the image view is gone! Just
disapeared and other items that are above it (set by relativeLayout)
are pushed down, like the imageview object did not exist at all. I
used the debuger and now I am sure, that each time I return to the
activity all Java-code steps pass correctly including
ButtonAnim = (AnimationDrawable) current;
and ButtonAnim .start();
but the image still is invisible.Does anyone have an ide abotu this?
Here are my codes:

            public void onCreate(Bundle savedInstanceState) {
   ...
firstLaunch = ture;
 abortButton = ((ImageView) findViewById(R.id.imageView1));
                abortButton.setOnClickListener(mButton01Listener);
 
abortButton.setBackgroundResource(R.drawable.aborrtlist);

                StateListDrawable background = (StateListDrawable)
abortButton.getBackground();
                Drawable current = background.getCurrent();
                if ( current instanceof AnimationDrawable)
                    ButtonAnim = (AnimationDrawable) current;
    ...
    }

In windows focus change I launch the animation:

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);

        if ( this.firstLaunch)
        {
            ButtonAnim .start();
           firstLaunch = false;
        }
    }

In the onClicl listener I just launch finish():

    OnClickListener mButton01Listener = new OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    };

Here the state list file:

<selector xmlns:android="http://schemas.android.com/apk/res/android";
android:constantSize="true">
    <item android:state_pressed="true"
          android:drawable="@drawable/abortbuttonpressed" /> <!--
pressed -->

    <item android:drawable="@drawable/abort_animation" /> <!-- default
-->
</selector>

And the animatio-list file:

<?xml version="1.0" encoding="utf-8"?>
 <animation-list xmlns:android="http://schemas.android.com/apk/res/
android"
    android:oneshot="false">
    <item android:drawable="@drawable/abortbuttonnormal0"
android:duration="500" />
    <item android:drawable="@drawable/abortbuttonnormal1"
android:duration="500" />
 </animation-list>


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

Reply via email to