问题:
在写一个手机通讯录界面,已完成界面,但是为了能够在屏幕上面显示更多内容,希望能够下往上滑的时候隐藏四个tabs,而在向下滑得时候再显示这四个tabs.
解决方案:
Android中Schrolling 主要包含两中方式:Dragging:拖动,Fling:扔,区别在于速度上面。
明显此刻的需求要求使用fling. 在onFling()方法中可以得到fling开始和结尾的x,y轴的位置,还有“扔”这个动作在x,y轴上的速度(velocity)。
注:屏幕的左上角为(0,0)...
实现:
1 注册手势监听器,为了能够向下兼容使用支持库。
private GestureDetectorCompat mDetector;
mDetector = new GestureDetectorCompat(this, new MyGestureListener()); // 绑定手势监听器
2 编写手势监听器
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
private static final String DEBUG_TAG = "Gestures";
@Override
public boolean onDown(MotionEvent event