《Android 開發藝術探索》讀後筆記 ---- 第三章 ---- view的事件體系

  • view 中的left和top 表示的是原始的位置信息,當view在平移時,發生改變的是x y translationx translationy
  • touchslop ViewConfiguration.get(getContext()).getScaledTouchSlop() 能夠獲取到系統定義的滑動最小承認距離
  • velocity tracker 速度檢測
  • gesturedetector 手勢檢測,用於輔助檢測用戶的單擊,滑動,長按、雙擊等行爲
  • scroller 彈性滑動對象,
Scroller mScroller = new Scroller(mContext);
private void smoothScrollTo(int destX, int destY) {
    int scrollX = getScrollX();
    int delta = destX - scrollX;
    mScroller.startScroll(scrollX, 0, delte, 0, 1000);
    invalidate();
}

public void computeScroll() {
    if (mScroller.computeScrollOffest()) {
        scrollTo(mScroller.getCurrX(), mScroller.getCurrY());
        postInvalidate();    
    }
}
  • 滑動衝突的解決方案 -- 外部攔截法: 父容器在ACTION_DOWN的時候不能返回true 由於這樣會致使後續的move和up都會直接交由父容器處理,Action_UP 返回false 由於這個up在外部攔截法的時候沒有多大意義。 -- 若是父容器在actiondown的時候攔截返回了true那麼後續的事件將所有交給父容器,哪怕actionup的時候返回了false 仍是會將actionup事件交由父容器 -- 內部攔截法:
相關文章
相關標籤/搜索