Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Set a touch listener on the view and compare the x and y spots</p> <p><a href="http://developer.android.com/reference/android/view/View.html#onTouchEvent(android.view.MotionEvent" rel="nofollow">http://developer.android.com/reference/android/view/View.html#onTouchEvent(android.view.MotionEvent</a>)</p> <p>Record when the starting positon where the user touches down</p> <p><a href="http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN" rel="nofollow">http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN</a></p> <p>and then track the offset.</p> <p>here is some view listener code I wrote for another question:</p> <pre><code>float initialX = 0; float initialY = 0; int currentFocusedChild = 0; List&lt;View&gt; children; public void walkElements() { final LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout); children = mainLayout.getFocusables(View.FOCUS_FORWARD); mainLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch(event.getAction()) { case MotionEvent.ACTION_DOWN: initialX = event.getX(); initialY = event.getY(); break; case MotionEvent.ACTION_MOVE: float diffX = event.getX() - initialX; float diffY = event.getY() - initialY; if(diffY &gt; 0) { if (currentFocusedChild &lt; children.size() - 1) { currentFocusedChild++; } } else { if (currentFocusedChild &gt; 0) { currentFocusedChild--; } } children.get(currentFocusedChild).setSelected(true); //Sleep for a period of time so the selection is slow enough for the user. Thread.sleep(300); break; case MotionEvent.ACTION_UP: children.get(currentFocusedChild).performClick(); break; } return false; } }); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload