• ViewDragHelper 使用


    ViewDragHelper 是谷歌2013年i/o大会上提出的,统一了view 的拖动处理,ViewDragHelper。

    使用ViewDragHelper场景:

    一般是view需要滑动拖拽,比如slidingmenu, listview item左右滑动效果等等。写在自定义的view中。

    使用ViewDragHelper 步骤:

    1,创建ViewDragHelper

    ViewDragHelper create(ViewGroup forParent, Callback cb)
    
     ViewDragHelper create(ViewGroup forParent, float sensitivity, Callback cb)
    View Code

    2,重写view  onInterceptTouchEvent

        public boolean onInterceptTouchEvent(MotionEvent ev) { return viewDragHelper.shouldInterceptTouchEvent(ev); } 

    3,重写view onTouchEvent

      public boolean onTouchEvent(MotionEvent event) {
            viewDragHelper.processTouchEvent(event);
            return true;
        }

    4, 若需要动画 重写view  computeScroll

     if (viewDragHelper.continueSettling(true)) {
                invalidate();
            }

    ViewDragHelper 重要方法:

    tryCaptureView                 捕获view 判断哪些view响应一系列事件

    onViewCaptured                         捕获到view时回调

    clampViewPositionHorizontal       view可移动的横向边界控制

    clampViewPositionVertical           view可移动的纵向边界控制

    onViewReleased                         手指释放时调用此方法

    onEdgeDragStarted                    边界拖动时调用

    getViewHorizontalDragRange       横向可拖动的范围  当子view可以抢到焦点时,导致不能拖动时,需要重写此方法。

    getViewVerticalDragRange            同上

    onViewDragStateChanged            状态发生变化时回调

    onViewPositionChanged                当拖动view的位置发生改变时回调

    onEdgeTouched                           触摸到边界时回调

     

  • 相关阅读:
    人机博弈,吃子棋游戏(一)基本介绍
    cesm下载备注
    mysql数据库批量高速插入
    持续学习
    顺序表的功能实现
    Broccoli & Babel使用演示样例
    rk3188调试记录
    Operation not allowed on a unidirectional dataset错误?
    dbExpress操作中用TDBGrid显示数据
    dbexpress连接mysql提示Operation not allowed on a unidirectional dataset
  • 原文地址:https://www.cnblogs.com/lihaolihao/p/4745297.html
Copyright © 2020-2023  润新知