<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                > 編寫:[Andrwyw](https://github.com/Andrwyw) - 原文:[http://developer.android.com/training/gestures/multi.html](http://developer.android.com/training/gestures/multi.html) 多點觸摸觸手勢是指在同一時間有多點(手指)觸碰屏幕。本節課程講述,如何檢測涉及多點的觸摸手勢。 ### 追蹤多點 當多個手指同時觸摸屏幕時,系統會產生如下的觸摸事件: - [ACTION_DOWN](http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN)-針對觸摸屏幕的第一個點。此事件是手勢的開端。第一觸摸點的數據在[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)中的索引總是0。 - [ACTION_POINTER_DOWN](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html#ACTION_POINTER_DOWN)-針對第一點后,出現在屏幕上的額外的點。這個點的數據在MotionEvent中的索引,可以通過[getActionIndex()](#)獲得。 - [ACTION_MOVE](http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_MOVE)-按下手勢時發生變化。 - [ACTION_POINTER_UP](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html#ACTION_POINTER_UP)-當非主要點(non-primary pointer)離開屏幕時,發送此事件。 - [ACTION_UP](http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_UP)-當最后一點離開屏幕時發送此事件。 你可以通過各個點的索引以及id,單獨地追蹤[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)中的每個點。 - Index:[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)把各個點的信息都存儲在一個數組中。點的索引值就是它在數組中的位置。大多數用來與點交互的[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)函數都是以索引值作為參數的,而不是點的ID。 - ID:每個點也都有一個ID,該ID在整個手勢期間一直存在,以便你單獨地追蹤每個點。 每個獨立的點在移動事件中出現的次序是不固定的。因此,從一個事件到另一個事件,點的索引值是可以改變的,但點的ID在它的生命周期內是保證不會改變的。使用[getPointerId()](http://developer.android.com/reference/android/view/MotionEvent.html#getPointerId(int))可以獲得一個點的ID,在手勢隨后的移動事件中,就可以用該ID來追蹤這個點。對于隨后一系列的事件,可以使用[findPointerIndex()](http://developer.android.com/reference/android/view/MotionEvent.html#findPointerIndex(int))函數,來獲得對應給定ID的點在移動事件中的索引值。如下: ~~~ private int mActivePointerId; public boolean onTouchEvent(MotionEvent event) { .... // Get the pointer ID mActivePointerId = event.getPointerId(0); // ... Many touch events later... // Use the pointer ID to find the index of the active pointer // and fetch its position int pointerIndex = event.findPointerIndex(mActivePointerId); // Get the pointer's current position float x = event.getX(pointerIndex); float y = event.getY(pointerIndex); } ~~~ ### 獲取MotionEvent的動作 你應該總是使用[getActionMasked()](http://developer.android.com/reference/android/view/MotionEvent.html#getActionMasked())函數(或者更好用[MotionEventCompat.getActionMasked()](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html#getActionMasked(android.view.MotionEvent))這個兼容版本)來獲取[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)的動作(action)。與舊的[getAction()](http://developer.android.com/reference/android/view/MotionEvent.html#getAction())函數不同的是,`getActionMasked()`是設計用來處理多點觸摸的。它會返回執行過的動作的掩碼值,不包括點的索引位。你可以使用`getActionIndex()`來獲得與該動作關聯的點的索引值。這在接下來的代碼段中可以看到。 > **注意**:這個樣例使用的是[MotionEventCompat](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html)類。該類在[Support Library](http://developer.android.com/tools/support-library/index.html)中。你應該使用[MotionEventCompat](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html)類,來提供對更多平臺的支持。需要注意的一點是,[MotionEventCompat](http://developer.android.com/reference/android/support/v4/view/MotionEventCompat.html)并不是[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)類的替代品。準確來說,它提供了一些靜態工具類函數,你可以把[MotionEvent](http://developer.android.com/reference/android/view/MotionEvent.html)對象作為參數傳遞給這些函數,來得到與事件相關的動作。 ~~~ int action = MotionEventCompat.getActionMasked(event); // Get the index of the pointer associated with the action. int index = MotionEventCompat.getActionIndex(event); int xPos = -1; int yPos = -1; Log.d(DEBUG_TAG,"The action is " + actionToString(action)); if (event.getPointerCount() > 1) { Log.d(DEBUG_TAG,"Multitouch event"); // The coordinates of the current screen contact, relative to // the responding View or Activity. xPos = (int)MotionEventCompat.getX(event, index); yPos = (int)MotionEventCompat.getY(event, index); } else { // Single touch event Log.d(DEBUG_TAG,"Single touch event"); xPos = (int)MotionEventCompat.getX(event, index); yPos = (int)MotionEventCompat.getY(event, index); } ... // Given an action int, returns a string description public static String actionToString(int action) { switch (action) { case MotionEvent.ACTION_DOWN: return "Down"; case MotionEvent.ACTION_MOVE: return "Move"; case MotionEvent.ACTION_POINTER_DOWN: return "Pointer Down"; case MotionEvent.ACTION_UP: return "Up"; case MotionEvent.ACTION_POINTER_UP: return "Pointer Up"; case MotionEvent.ACTION_OUTSIDE: return "Outside"; case MotionEvent.ACTION_CANCEL: return "Cancel"; } return ""; } ~~~ 關于多點觸摸的更多內容以及示例,可以查看[拖拽與縮放](#)章節。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看