tabhost+滚动条的效果实现
来源:互联网 发布:java初学者源代码 编辑:程序博客网 时间:2024/06/05 15:39
方案1:
tabhost+viewPager参考连接:
http://blog.csdn.net/qjlhlh/article/details/7788444
github上有更强大,以封装好的相关类库
连接为:https://github.com/LuckyJayce/ViewPagerIndicator
方案2:
在tabhost所在xml写一个View占位符,摆在tabhost之上;根据选项卡的个数代码计算占位符宽度;
关键代码:
代码计算滚动条宽度:
/** * 初始滚动条长度 */ private void InitImageView() { topSelect = (ImageView) findViewById(R.id.tab_top_select); //有几张图片就让其便宜屏幕的多少分之一 int screenW = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth(); int offset = screenW / 4;// 计算偏移量 Matrix matrix = new Matrix(); matrix.postTranslate(0, 0); topSelect.setImageMatrix(matrix);// 设置动画初始位置 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) topSelect.getLayoutParams(); params.width = offset; topSelect.setLayoutParams(params); }
在tabhost切换时执行
/** * 移动tab选中标识图片 * * @param selectIndex */ public void moveTopSelect(int selectIndex) {// 起始位置中心点 TabWidget tabwidget = mFragmentTabHost.getTabWidget(); int startMid = ((View) tabwidget.getChildAt(mCurSelectTabIndex)).getLeft() + ((View) tabwidget.getChildAt(mCurSelectTabIndex)).getWidth() / 2;// 起始位置左边位置坐标 int startLeft = startMid - topSelect.getWidth() / 2;// 目标位置中心点 int endMid = ((View) tabwidget.getChildAt(selectIndex)).getLeft() + ((View) tabwidget.getChildAt(selectIndex)).getWidth() / 2;// 目标位置左边位置坐标 int endLeft = endMid - topSelect.getWidth() / 2; TranslateAnimation animation = new TranslateAnimation(startLeft, endLeft - topSelect.getLeft(), 0, 0); animation.setDuration(200); animation.setFillAfter(true); topSelect.bringToFront(); topSelect.startAnimation(animation);// 改变当前选中按钮索引 mCurSelectTabIndex = selectIndex; Log.i("fs", "endMid " + endMid + " startLeft " + startLeft + " endLeft" + (endLeft - topSelect.getLeft())); }
参考连接:
http://blog.csdn.net/jdsjlzx/article/details/7555408
比较:使用方案1,手势操作也支持,不过给的demo是滚动条向下的;
方案2,手势操作需要另加,滚动条调位置比较方便
0 0
- tabhost+滚动条的效果实现
- 滚动条效果实现
- js实现滚动条效果
- css实现滚动条效果
- 自定义滚动条效果实现
- Fragment实现tabhost的效果
- 实现div跟着滚动条动的效果
- 纯CSS实现的表格滚动条效果
- div的滚动条效果
- 流行的滚动条效果
- 滚动条的实现;
- Android 导航条效果实现(一) TabActivity+TabHost
- jquery使用div实现滚动条效果
- Delphi中TFlowPanel实现滚动条效果
- android tv 实现颜色条滚动效果
- div+js实现自制滚动条效果
- js实现动态拖动滚动条效果
- Android实现滚动条下拉反弹效果
- hadoop案例实现之WordCount (计算单词出现的频数)
- 3、强制类型转换、as和is
- 全面解析Activity的生命周期
- 2015湘潭邀请赛 Segment Tree
- git
- tabhost+滚动条的效果实现
- 算法中常见时间复杂度的比较
- iOS相关,过年回来电脑上的证书都失效了,求大神!
- xilinx千兆以太网与万兆以太网IP接口
- HBase shell的基本用法
- Ubuntu下挂载远程目录方法
- 1063. Set Similarity (25)
- Salt-api调用模块saltapi.py
- 再谈spring mvc中的root/child WebApplicationContext