1

查询:

什么是同时制作动画和改变视图位置的可能解决方案,比如:鸟飞?

动画的 arrow_anim.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/arrow" android:duration="1000" />
    <item android:drawable="@drawable/arrow1" android:duration="1000" />
    <item android:drawable="@drawable/arrow2" android:duration="1000" />
    <item android:drawable="@drawable/arrow3" android:duration="1000" />
</animation-list>

动画的代码片段:

imageView.setBackgroundResource(R.drawable.arrow_anim);
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
anim.start();

这就像站立的动画,我需要更改动画及其位置。

什么课程帮助我实现了这种鸟类功能。

为我正在尝试的代码编辑 1

imageView.setBackgroundResource(R.drawable.movie);
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
anim.start();


TranslateAnimation trans = new TranslateAnimation(0, 0,
                    TranslateAnimation.ABSOLUTE, 250, 0, 0,
                    TranslateAnimation.ABSOLUTE, 250);
trans.setDuration(0);


AnimationSet animationSet=new AnimationSet(true);
animationSet.addAnimation(trans);
imageView.startAnimation(animationSet);

但这不能同时工作。如果有什么遗漏,建议我改正。

4

2 回答 2

0

这可能会给你一个想法..

private void runAnimation(View view){

        ValueAnimator vAnimator = ObjectAnimator.ofFloat(view, "alpha", 1,0f);
        vAnimator.setDuration(1000);
        vAnimator.setRepeatMode(ValueAnimator.REVERSE);
        vAnimator.setRepeatCount(ValueAnimator.INFINITE);

        ValueAnimator vAnimator2 = ObjectAnimator.ofFloat(view, "translationX", 100f);
        vAnimator2.setDuration(1000);
        vAnimator2.setRepeatMode(ValueAnimator.REVERSE);
        vAnimator2.setRepeatCount(ValueAnimator.INFINITE);

        AnimatorSet set = new AnimatorSet();
        set.playTogether(vAnimator,vAnimator2);
        set.setStartDelay(0);

        set.start();

    }
于 2013-09-20T10:12:43.093 回答
0

既然我知道你想要什么,你就可以start()开始AnimationDrawable翻译动画了imageView

View.startAnimation(Animation);
于 2013-09-20T11:00:58.687 回答