滑动隐藏标题栏布局ListView
来源:互联网 发布:开淘宝微店能赚钱吗 编辑:程序博客网 时间:2024/05/21 10:17
由于手机屏幕有限,有时候列表展示时,为了尽可能多的为用户展示列表数据,当用户向上滑动手指,查看更多数据时,可以把标题栏隐藏,从而为用户展示更多的数据。
向上滑动时,隐藏标题栏
实现起来也比较简单,步骤如下:
- 为ListView添加监听手势
- 当用户向上滑动时隐藏标题栏
- 当用户向下滑动时显示标题栏
总体思路比较简单,为ListView添加一个onTouchListener,判断用户当前触发的手势,进行相应的视图布局的显示和隐藏。关于视图的显示的隐藏有很多种方式,我们这里使用的是属性动画。
mListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mFirstY = event.getY(); break; case MotionEvent.ACTION_MOVE: mCurrentY = event.getY(); if (mCurrentY - mFirstY > mTouchSlop) { // 下滑 显示titleBar showHideTitleBar(true); } else if (mFirstY - mCurrentY > mTouchSlop) { // 上滑 隐藏titleBar showHideTitleBar(false); } break; case MotionEvent.ACTION_UP: break; } return false; } });
private void showHideTitleBar(boolean tag) { if (mAnimatorTitle != null && mAnimatorTitle.isRunning()) { mAnimatorTitle.cancel(); } if (mAnimatorContent != null && mAnimatorContent.isRunning()) { mAnimatorContent.cancel(); } if (tag) { mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), 0); mAnimatorContent = ObjectAnimator.ofFloat(mListView, "translationY", mListView.getTranslationY(), getResources().getDimension(R.dimen.title_height)); } else { mAnimatorTitle = ObjectAnimator.ofFloat(mTitle, "translationY", mTitle.getTranslationY(), -mTitle.getHeight()); mAnimatorContent = ObjectAnimator.ofFloat(mListView, "translationY", mListView.getTranslationY(),0); } mAnimatorTitle.start(); mAnimatorContent.start(); }
这里为了有较好的用户体验使用了一个属性动画,当然你也可以简单的使用Visible属性来控制标题栏的显示和隐藏,需要注意的是,注意计算标题栏显示隐藏时,ListView位置进行相应的改变,demo中同样也使用的属性动画进行相应位置的改变。
源码地址
2 0
- 滑动隐藏标题栏布局ListView
- 实现滑动隐藏标题栏布局ListView所碰到的问题
- 简易:ListView滑动隐藏标题栏
- android ListView向上滑动隐藏标题,下拉显示标题栏
- android ListView向上滑动隐藏标题,下拉显示标题栏
- android ListView向上滑动隐藏标题,下拉显示标题栏
- android ListView向上滑动隐藏标题,下拉显示标题栏
- android ListView向上滑动隐藏标题,下拉显示标题栏
- 滑动隐藏标题栏
- 滑动隐藏和显示标题栏
- 简单代码实现向上滑动隐藏标题栏
- ListView上下滑动渐显(渐消)标题栏
- PullToRefreshListView滑动布局隐藏问题
- 仿微信侧滑ListView item滑动布局
- ListView+头部向上滑动标题栏渐显以及ScrollView向上滑动标题栏渐显
- 实现ScrollView滑动时标题栏的隐藏效果
- iOS-UIScrollview滑动时标题栏自动隐藏和显示效果
- 实现ScrollView滑动时标题栏的隐藏效果
- android使用NDK编译curl库
- 解决Develop证书和Distribution的证书签发者无效问题
- 各种正则表达式
- BSOJ3991:聪聪可可 点分治
- 爬虫学习 基本打开网页操作
- 滑动隐藏标题栏布局ListView
- 创建字符串对象的时候,使用字面值和使用new String()构造器这两种方式有什么不同?
- junit 使用JUnit测试预期异常
- 微信红包随机算法初探
- android5.1后新增shadow$_monitor_和shadow$_klass_ ,导致反射无效
- linux开发调试工具---GDB的使用
- 流媒体技术
- CodeForces NO.197B Limit
- round、ceil、floor