android 动画闪烁问题,android平移动画闪烁问题

当我们应用android平移动画时,一般会给动画一个监听,当动画结束时,会将view的位置重新绘制到我们想要的位置,因为平移动画并没与真的改变控件的实际位置.

代码如下:

Animation animation = new TranslateAnimation(0, 0, 0, -mTop);

animation.setDuration(ANI_TIME);

animation.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

//动画结束后更新view到终点位置

mTopView.layout(left, top, right, bottom);

}

@Override

public void onAnimationRepeat(Animation animation) {

}

});

mTopView.startAnimation(animation);

但是实际使用的时候,当更新实际位置的时候,view会有跳动,在stackoverflow中有人贴出了解决方案

代码如下:

Animation animation = new TranslateAnimation(0, 0, 0, -mTop);

animation.setDuration(ANI_TIME);

animation.setAnimationListener(new Animation.AnimationListener() {

@Override

public void onAnimationStart(Animation animation) {

}

@Override

public void onAnimationEnd(Animation animation) {

//防止跳动

TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);

animation.setDuration(1);

mTopView.startAnimation(animation);

//动画结束后更新view到终点位置

mTopView.layout(left, top, right, bottom);

}

@Override

public void onAnimationRepeat(Animation animation) {

}

});

mTopView.startAnimation(animation);

在实际写的时候,偶然发现另一种方式也是有效的,不过这种有点违反直觉,就是倒着写动画,先把view更新到终点位置,代码如下:

//由于更新到终点位置,坐标参考以终点为参考系

Animation animation = new TranslateAnimation(0, 0, mTop, 0);

animation.setDuration(ANI_TIME);

mTopView.startAnimation(animation);

//更新到终点位置

mTopView.layout(left, top, right, bottom);

但是,为何出现view跳动的原因一直没找到分析的文章,若有人知道望请告知.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值