/**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);
}
}