TranslateAnimation动画结束后位置闪烁问题

主要代码如下:

float fromXDelta = context.length;
TranslateAnimation translateAnimation =null;
if (this.context.oldTabViewIndex < this.context.curTabViewIndex) {
fromXDelta = context.length * (this.context.curTabViewIndex - this.context.oldTabViewIndex);
translateAnimation = new TranslateAnimation(0,
fromXDelta, 0.0F, 0.0F);
}else {
fromXDelta = context.length * (this.context.oldTabViewIndex - this.context.curTabViewIndex);
translateAnimation = new TranslateAnimation(0,
fromXDelta*-1, 0.0F, 0.0F);
}
translateAnimation.setAnimationListener(new AnimationListener(){

@Override
public void onAnimationEnd(Animation animation) {
RelativeLayout.LayoutParams aLayoutParams = (RelativeLayout.LayoutParams) context.tab_front_bg
.getLayoutParams();
aLayoutParams.setMargins(context.curTabViewIndex*context.length, 0, 0, 0);
context.tab_front_bg.setLayoutParams(aLayoutParams);
// context.tab_front_bg.clearAnimation();//解决移动后闪烁现象 ①
TranslateAnimation anim = new TranslateAnimation(0,0,0,0);   ②
context.tab_front_bg.setAnimation(anim);               ③
}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub

}

@Override
public void onAnimationStart(Animation animation) {

}
});
translateAnimation.setDuration(200);
context.tab_front_bg.startAnimation(translateAnimation);


如没有 ① ② ③ 代码,动画结束后停在动画结束的位置后闪烁一下,  加上①处代码  可以解决 不过Listview会有问题,  改用②③解决

posted @ 2011-10-29 19:36  yyyyy5101  Views(4346)  Comments(0Edit  收藏  举报