自定义tabhost实现tab切换动画
来源:互联网 发布:致富360是什么软件 编辑:程序博客网 时间:2024/06/06 14:22
<pre name="code" class="java"><pre name="code" class="java">
//首先从anim文件夹下加载动画xml
public CustomTabHost(Context context, AttributeSet attrs) {super(context, attrs);slideLeftIn = AnimationUtils.loadAnimation(context,R.anim.slide_left_in);slideLeftOut = AnimationUtils.loadAnimation(context,R.anim.slide_left_out);slideRightIn = AnimationUtils.loadAnimation(context,R.anim.slide_right_in);slideRightOut = AnimationUtils.loadAnimation(context,R.anim.slide_right_out);}
//继承自TabHost并复写<span style="font-family: Arial, Helvetica, sans-serif;">setCurrentTab方法即可实现自定义切换动画效果</span>
@Overridepublic 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(slideRightOut);} else if (currentTabIndex == 0 && index == (tabCount - 1)) {//处理边界滑动getCurrentView().startAnimation(slideLeftOut);} else if (index > currentTabIndex) {//非边界情况下从右往左滑动getCurrentView().startAnimation(slideLeftOut);} else if (index < currentTabIndex) {//非边界情况下从左往右滑动getCurrentView().startAnimation(slideRightOut);}}super.setCurrentTab(index);//不知道为何要放在这里,放在其他地方效果就出不来了//设置即将显示的tab页的动画View currentView=getCurrentView();if (currentTabIndex == (tabCount - 1) && index == 0){//处理边界滑动if(currentView!=null)currentView.startAnimation(slideLeftIn);} else if (currentTabIndex == 0 && index == (tabCount - 1)) {//处理边界滑动if(currentView!=null)currentView.startAnimation(slideRightIn);} else if (index > currentTabIndex) {//非边界情况下从右往左滑动if(currentView!=null)currentView.startAnimation(slideRightIn);} else if (index < currentTabIndex) {//非边界情况下从左往右滑动if(currentView!=null)currentView.startAnimation(slideLeftIn);}}
参考自:http://helloandroid.iteye.com/blog/1181827,里面还介绍了如何实现手势滑动。
0 0
- 自定义tabhost实现tab切换动画
- Android:TabHost实现Tab切换
- Android:TabHost实现Tab切换
- Android:TabHost实现Tab切换
- Android:TabHost实现Tab切换
- Android-TabHost实现Tab切换
- tabhost+自定义tab的demo
- TabHost切换动画(android)
- 自定义TabHost实现背景图片随选项卡切换滑动效果
- 自定义TabHost实现背景图片随选项卡切换滑动效果
- 自定义TabHost实现背景图片随选项卡切换滑动效果
- 自定义TabHost实现背景图片随选项卡切换滑动效果
- 底部Tab的实现(tabhost)
- 自定义的tab切换
- Tab切换动画滑动效果的一个简单实现
- 纯CSS3实现动画不规则的tab标签切换代码
- 仿鲁大师界面(实现启动动画和TabHost选项卡切换时滑动动画)
- JavaScript 动画之tab切换
- 在MFC项目中使用Google Earth COM API示例
- EL和OGNL用处
- 采畅云服务——销售易
- 新增磁盘不重启识别
- navigationBar添加背景图片
- 自定义tabhost实现tab切换动画
- 【AC大牛陈鸿的ACM总结贴】【ID AekdyCoin】人家当初也一样是菜鸟
- 每日练手 8.19
- ADF的生命周期介绍
- Oracle expdp/impdp工具使用
- Android-本地广播提高安全性
- CentOS(RedHat)中sendmail和sm-client启动慢的解决方法
- Google Chrome Source Code 浏览器源码(下载)
- 为什么调用 FragmentPagerAdapter.notifyDataSetChanged() 并不能更新其 Fragment?