0

我想做的是通过以下方式将图像从当前位置动画到新位置

XML

<?xml version="1.0" encoding="utf-8"?>
<set
    xmlns:android="http://schemas.android.com/apk/res/android">

<translate
    xmlns:android       ="http://schemas.android.com/apk/res/android"
    android:fromXDelta  ="0"
    android:toXDelta    ="0"
    android:fromYDelta  ="0"
    android:toYDelta    ="-100"
    android:duration    ="2000"
    android:fillAfter   ="true"
     />

</set>

Java 代码

        ImageView   logo01             =    (ImageView) findViewById(R.id.logo01);
        Animation   animation01        =    AnimationUtils.loadAnimation(this, R.anim.translate);
        animation01.reset();
        logo01.clearAnimation();
        logo01.startAnimation(animation01);

但是,在动画结束时,图像会重新回到原来的位置。我们如何才能避免这种情况,以便最终图像处于新位置。

4

1 回答 1

0

我曾经有过类似的问题。我最终使用了动态动画而不是 xml:

TranslateAnimation anim = new TranslateAnimation(0,0,0,-100);
anim.setDuration(2000);
anim.setFillAfter(true);
logo01.setAnimation(anim);
于 2013-05-04T18:32:26.927 回答