我需要在一秒钟内将动画平移到 X (150) 和 Y (100) 位置来为我的 View 设置动画。使用此代码运行良好:
Animation translate = new
TranslateAnimation(0, 150 - view.getLeft(), 0, 100 - view.getTop());
translate.setDuration(1000);
view.setAnimation(translate);
translate.start();
但是当动画完成时,我需要 View 保持在这个位置 (150, 100),然后我调用了 setAnimationListener 并执行了以下操作:
@Override
public void onAnimationEnd(Animation animation) {
if (animation == translate) {
RelativeLayout.LayoutParams params = new
RelativeLayout.LayoutParams(view.getWidth(), view.getHeight());
params.topMargin = 100;
params.leftMargin = 150;
view.setLayoutParams(params);
}
}
问题在于,在动画结束时, View 闪烁一次(非常快,几乎难以察觉),然后 View 移动到另一个位置,非常接近所需位置 (150, 100),但不完全一样。
如果我设置translate.setFillAfter(true)它就可以工作。但是,如果我需要将另一个动画应用到同一 View ,它会按预期工作吗?
最佳答案
您需要添加以下内容:
fillAfter=true
fillEnabled=true
关于java - 平移动画 - 结束位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24015841/