开发者

image animation in android

开发者 https://www.devze.com 2023-01-09 09:33 出处:网络
I have to repeat the image sequence I am using with Thread and AnimationDrawable but it is not working continuously. I don\'t want to stop this animation until next activity is started through button

I have to repeat the image sequence I am using with Thread and AnimationDrawable but it is not working continuously. I don't want to stop this animation until next activity is started through button click event.

Here is my java code:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);{

final ImageView splashImage=(ImageView)findViewById(R.id.heartFunction);
     splashImage.setBackgroundResource(R.drawable.slide_right);
  splashAnimation = (AnimationDrawable) splashImage.getBackground();
}




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

    if ( isFocused ) {
        //isFocused = false;

        splashAnimation.start();
        var=false;
        new Thread(new Runnable() {
        public void run() {
            try {
                Thread.sleep(SPLASH_DISPLAY_LENGTH);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

slide_right.xml:-

<?xml version="1.0" en开发者_开发知识库coding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">

<item android:drawable="@drawable/heartcolored0" android:duration="200" />
<item android:drawable="@drawable/heartcolored2" android:duration="200" />
<item android:drawable="@drawable/heartcolored4" android:duration="200" />
<item android:drawable="@drawable/heartcolored5" android:duration="200" />
<item android:drawable="@drawable/heartcolored6" android:duration="200" />
<item android:drawable="@drawable/heartcolored7" android:duration="200" />
<item android:drawable="@drawable/heartcolored8" android:duration="200" />
<item android:drawable="@drawable/heartcolored9" android:duration="200" />
<item android:drawable="@drawable/heartcolored10" android:duration="200" />
<item android:drawable="@drawable/heartcolored11" android:duration="200" />
<item android:drawable="@drawable/heartcolored12" android:duration="200" />
<item android:drawable="@drawable/heartcolored13" android:duration="200" />

</animation-list>


If you want your animation to contiuously run then you need to set android:oneshot="false"

You were saying before to only run through once.

If you want an animation to run until you click the screen to go to the next activity. Start the animation when the onWindowFocusChanged function

@Override
public void onWindowFocusChanged(boolean hasFocus){
    splashanimation.start();
}

Then use an onTouchEvent to catch the touch, start a new activity and finish the old activity.

@Override
public boolean onTouchEvent(MotionEvent event){
     if (event.getAction() == MotionEvent.ACTION_DOWN) {
          Intent i = new Intent(Anim.this, Main.class);
          startActivity(i);
          finish();
     }
return true;
}

Hope this helps, your question is very hard to read/understand.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号