Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use to extends simple gesture listener.My code is roughly pasted here.This is only to give some idea about that.I have done this when creating horizontal scroll view.</p> <pre><code>setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (mGestureDetector.onTouchEvent(event)) { return true; } else if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { int scrollX = getScrollX(); int featureWidth = v.getMeasuredWidth(); mActiveFeature = ((scrollX + (featureWidth/2))/featureWidth); int scrollTo = mActiveFeature*featureWidth; smoothScrollTo(scrollTo, 0); return true; } else { return false; } } } </code></pre> <p><strong>Simple GestureListener:</strong></p> <pre><code>class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { int featureWidth = getMeasuredWidth(); mActiveFeature = (mActiveFeature &lt; (mItems.size() - 1))? mActiveFeature + 1:mItems.size() -1; smoothScrollTo(mActiveFeature*featureWidth, 0); return true; } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { int featureWidth = getMeasuredWidth(); mActiveFeature = (mActiveFeature &gt; 0)? mActiveFeature - 1:0; smoothScrollTo(mActiveFeature*featureWidth, 0); return true; } } catch (Exception e) { Log.e("Fling", "There was an error processing the Fling event:" + e.getMessage()); } return false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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