1. 程式人生 > >TranslateAnimation動畫結束後位置閃爍問題

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會有問題,  改用②③解決.

轉載自http://www.cnblogs.com/yyyyy5101/archive/2011/10/29/2228781.html