fleep滑动切换tab(切换带动画)

[color=red]从右向左滑动,tab页切换后的效果[/color]
[img]http://dl.iteye.com/upload/attachment/561291/46bb2c05-2650-3877-9175-447de4e15fc0.png[/img]

[img]http://dl.iteye.com/upload/attachment/561293/b397b387-50dc-30bd-b963-20e79747ba00.png[/img]

[color=red]主要代码1:继承TabHost覆写setCurrentTab(int index)方法[/color]
@Override
public void setCurrentTab(int index) {
//index为要切换到的tab页索引,currentTabIndex为现在要当前tab页的索引
int currentTabIndex = getCurrentTab();

//设置当前tab页退出时的动画
if (null != getCurrentView()){//第一次进入MainActivity时,getCurrentView()取得的值为空
if (currentTabIndex == (tabCount - 1) && index == 0) {//处理边界滑动
getCurrentView().startAnimation(slideLeftOut);
} else if (currentTabIndex == 0 && index == (tabCount - 1)) {//处理边界滑动
getCurrentView().startAnimation(slideRightOut);
} else if (index > currentTabIndex) {//非边界情况下从右往左fleep
getCurrentView().startAnimation(slideLeftOut);
} else if (index < currentTabIndex) {//非边界情况下从左往右fleep
getCurrentView().startAnimation(slideRightOut);
}
}

super.setCurrentTab(index);

//设置即将显示的tab页的动画
if (currentTabIndex == (tabCount - 1) && index == 0){//处理边界滑动
getCurrentView().startAnimation(slideLeftIn);
} else if (currentTabIndex == 0 && index == (tabCount - 1)) {//处理边界滑动
getCurrentView().startAnimation(slideRightIn);
} else if (index > currentTabIndex) {//非边界情况下从右往左fleep
getCurrentView().startAnimation(slideLeftIn);
} else if (index < currentTabIndex) {//非边界情况下从左往右fleep
getCurrentView().startAnimation(slideRightIn);
}
}


[color=red]2:实现OnGestureListener接口,覆写onFling()方法[/color]
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {
if (e1.getX() - e2.getX() <= (-FLEEP_DISTANCE)) {//从左向右滑动
currentTabID = tabHost.getCurrentTab() - 1;
if (currentTabID < 0) {
currentTabID = tabHost.getTabCount() - 1;
}
} else if (e1.getX() - e2.getX() >= FLEEP_DISTANCE) {//从右向左滑动
currentTabID = tabHost.getCurrentTab() + 1;
if (currentTabID >= tabHost.getTabCount()) {
currentTabID = 0;
}
}
tabHost.setCurrentTab(currentTabID);
return false;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值