/**ide
* 页面变化监听字体
* 动画
* @author wdj 2015年5月14日spa
*/.net
private int previousOffset = 0;图片
public class IndexTabPageChangeListener implements OnPageChangeListener {get
@Overrideanimation
public void onPageScrollStateChanged(int arg0) {it
}io
@Override
public void onPageScrolled(final int arg0, final float arg1, int arg2) {
int offset = 0;
// 取得该控件的实例
if (currIndex == arg0) {
offset = (int) (currIndex * barText.getWidth() + arg1 * barText.getWidth());
} else if (currIndex > arg0) {
offset = (int) (currIndex * barText.getWidth() - (1 - arg1) * barText.getWidth());
}
//为了保证流畅度,使用动画类
Animation animation = new TranslateAnimation(previousOffset, offset, 0, 0);
animation.setFillAfter(true);// True:图片停在动画结束位置
animation.setDuration(300);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// 改变tab title的字体颜色
changeLabelColor(arg0);
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
});
barText.startAnimation(animation);
previousOffset = offset;
}
@Override
public void onPageSelected(final int arg0) {
// // TODO Auto-generated method stub
currIndex = arg0;
changeLabelColor(arg0);
}
}