动画像:鸟飞?[完成]

时间:2013-09-20 06:46:57

标签: android animation android-animation

Qus:

制作动画并同时更改视图位置的可能解决方案是什么?鸟飞?

动画的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);

但这不能同时发挥作用。如果缺少某些东西,建议我纠正它。

2 个答案:

答案 0 :(得分: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();

    }

答案 1 :(得分:0)

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

View.startAnimation(Animation);