跨屏多次帧动画动作 [英] Frame animation moves across screen multiple times

查看:188
本文介绍了跨屏多次帧动画动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一帧动画(在一个回路内ImageViews)和我谨在屏幕上用动画()translationXBy(X)。我想要的应用程序,以保持横跨只要应用程序是移动上的动画。像普通的循环()不会出于某种原因像我这样的新手,不明白的工作。下面是一些code:

 私人ImageView的事情;
私人AnimationDrawable movingthing;
私人诠释宽度;保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    事情=(ImageView的)findViewById(R.id.pics);
    thing.setImageResource(R.drawable.thingthatmoves);
    movingthing =(AnimationDrawable)thing.getDrawable();
    DisplayMetrics displaymetrics =新DisplayMetrics();
    。getWindowManager()getDefaultDisplay()getMetrics(displaymetrics)。
    宽度= displaymetrics.widthPixels;//发生两次
公共无效的send(){
    moveThatThing();
    最后的处理程序处理程序=新的处理程序();
    handler.postDelayed(新的Runnable(){
    公共无效的run(){
        moveThatThing();
        }
    },3000);
}公共无效moveThatThing(){
    thing.setX(-10);
    X =宽度;
    movingthing.start();
    。thing.animate()setDuration(3000);
    thing.animate()translationXBy(x)的。
}


解决方案

尝试使用可运行。

添加处理您的onCreate方法:

 处理程序H =新的处理程序();
h.postDelayed(移动,0);

然后在此可运行添加到您的类

  Runnable的举动=新的Runnable(){
    @覆盖
    公共无效的run(){
            moveThatThing();
            h.postDelayed(移动,3000);
        }
};

我在一个基本的应用程序测试,它为我工作。

I have a frame animation (two ImageViews in a loop) and I move that across the screen with animate().translationXBy(x); I want the app to keep moving the animation across as long as the app is on. Regular loops like for() do not work for some reason a newbie like me doesn't understand. Here is some code:

private ImageView thing;
private AnimationDrawable movingthing;
private int width;

protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    thing= (ImageView)findViewById(R.id.pics);
    thing.setImageResource(R.drawable.thingthatmoves);
    movingthing = (AnimationDrawable)thing.getDrawable();
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    width = displaymetrics.widthPixels;

// happens twice
public void send(){
    moveThatThing();
    final Handler handler = new Handler();
    handler.postDelayed(new Runnable(){
    public void run(){
        moveThatThing();
        }
    }, 3000);
}

public void moveThatThing(){
    thing.setX(-10);
    x = width;
    movingthing.start();
    thing.animate().setDuration(3000);
    thing.animate().translationXBy(x);
}

解决方案

Try using a runnable.

Add a handler to your oncreate method:

Handler h=new Handler();
h.postDelayed(move, 0);

And then add in this runnable to your class

Runnable move = new Runnable() {
    @Override
    public void run() {
            moveThatThing();
            h.postDelayed(move, 3000);
        }
};

I tested in a basic application and it worked for me.

这篇关于跨屏多次帧动画动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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