在android系统的图像动画 [英] image animation in android

查看:252
本文介绍了在android系统的图像动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重复我与线程和AnimationDrawable使用图像序列,但它不是连续工作。我不想停止这种动画,直到下一个活动是通过按钮点击事件开始。

下面是我的Java code:

 公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState); {最终的ImageView的splashimage =(ImageView的)findViewById(R.id.heartFunction);
     splashImage.setBackgroundResource(R.drawable.slide_right);
  splashAnimation =(AnimationDrawable)splashImage.getBackground();
}
公共无效onWindowFocusChanged(布尔hasFocus){
    super.onWindowFocusChanged(hasFocus);    如果(isFocused){
        // isFocused = FALSE;        splashAnimation.start();
        VAR = FALSE;
        新主题(新的Runnable接口(){
        公共无效的run(){
            尝试{
                视频下载(SPLASH_DISPLAY_LENGTH);
            }赶上(InterruptedException的E){
                e.printStackTrace();
            }
        }
    })。开始();
}

slide_right.xml: -

 <?XML版本=1.0编码=UTF-8&GT?;
<动画列表
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:单稳=真正的><项目机器人:可绘制=@绘制/ heartcolored0机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored2机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored4机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored5机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored6机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored7机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored8机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored9机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored10机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored11机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored12机器人:时间=200/>
<项目机器人:可绘制=@绘制/ heartcolored13机器人:时间=200/>< /动漫列表>


解决方案

如果你希望你的动画contiuously运行,那么你需要设置的android:单稳=FALSE

您是说,之前只能通过运行一次。

如果你想要一个动画运行,直到您点击屏幕进入到下一个活动。启动动画时onWindowFocusChanged功能

  @覆盖
公共无效onWindowFocusChanged(布尔hasFocus){
    splashanimation.start();
}

然后使用onTouchEvent搭上触摸,开始一个新的活动,并完成了原有的业务。

  @覆盖
公共布尔onTouchEvent(MotionEvent事件){
     如果(event.getAction()== MotionEvent.ACTION_DOWN){
          意图I =新意图(Anim.this,Main.class);
          startActivity(ⅰ);
          完();
     }
返回true;
}

希望这有助于你的问题是很难读/理解。

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" encoding="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.

这篇关于在android系统的图像动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆