首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android动画

问Android动画
EN

Stack Overflow用户
提问于 2011-05-24 20:55:07
回答 5查看 479关注 0票数 0

我试图使用动画将图像从一个地方移动到另一个地方,但在将它移回原始位置后,如何将其停止到移动的位置本身。

EN

回答 5

Stack Overflow用户

发布于 2011-05-24 21:27:33

要让图像位于动画的最后位置,请尝试执行以下操作:

代码语言:javascript
复制
TranslationAnimation ta = new TranslateAnimation(fromX, toX, 0, 0);
ta.setDuration(1000);
ta.setFillAfter(true); // this will let the image in the last place of the Animation
imageView.startAnimation(ta);
票数 1
EN

Stack Overflow用户

发布于 2015-03-31 15:29:53

动画完成后,使用方法setFillAfter(true),使最后一个动画状态保持不变:

如果fillAfter为true,则此动画执行的变换在完成时将持续。

Animation.setFillAfter/Before - Do they work/What are they for?

如果需要执行更具体的操作,还可以设置动画侦听器并在动画结束时移动对象:

代码语言:javascript
复制
animation1.setAnimationListener(new AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //change according to your needs
                myView.setX(0);
            }

            @Override
            public void onAnimationRepeat(Animation animation) { }
        });
票数 1
EN

Stack Overflow用户

发布于 2018-05-13 18:50:57

终于找到了一种变通的方法,正确的方法是setFillAfter(true),

如果你想在xml中定义你的动画,你应该这样做

代码语言:javascript
复制
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    android:fillAfter="true">

<translate 
    android:fromXDelta="0%"
    android:toXDelta="-100%"
    android:duration="1000"/>

</set>

您可以看到,我已经在set标记中定义了filterAfter="true“,如果您尝试

在翻译标签中定义它,它不会工作,可能是框架中的错误!!

然后在代码中

代码语言:javascript
复制
Animation anim = AnimationUtils.loadAnimation(this, R.anim.slide_out);
someView.startAnimation(anim);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6110749

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档