Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As in the documented said</p> <p><a href="http://developer.android.com/reference/android/widget/ScrollView.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/widget/ScrollView.html</a></p> <blockquote> <p>ScrollView only supports vertical scrolling. For horizontal scrolling, use HorizontalScrollView.</p> </blockquote> <p>So, I need to ask why did you really want to use your custom scrollview?</p> <p>If you only intend to be able to scroll, you might no need to use it</p> <p>only RelativeLayout.scrollBy(x,y); is enough</p> <p>You could look at this link</p> <p><a href="https://stackoverflow.com/questions/2044775/scrollview-vertical-and-horizontal-in-android">Scrollview vertical and horizontal in android</a></p> <h1>EDIT</h1> <p>Ok, So you need to make the gesture detect the fling over the ScrollView.</p> <p>You could make it in your Activity without making custom ScrollView also</p> <p>first, you need to </p> <pre><code>implements OnGestureListener, OnTouchListener, GestureDetector.OnDoubleTapListener </code></pre> <p>and in your class create gestureDetector</p> <pre><code>gd = new GestureDetector(this); </code></pre> <p>and your ScrollView object, just declared </p> <pre><code>sv.setOnTouchListener(this); </code></pre> <p>then, in override onTouch method</p> <pre><code>@Override public boolean onTouch(View v, MotionEvent event) { onTouchEvent(event); // throw to onTouchEvent return false; } </code></pre> <p>and in override onTouchEvent method</p> <pre><code>@Override public boolean onTouchEvent(MotionEvent me) { return gd.onTouchEvent(me); // gd = gesturedetector } </code></pre> <p>now override your onFling method like this</p> <pre><code>private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_THRESHOLD_VELOCITY = 200; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { // "Left Swipe" vf.showPrevious(); // vf = ViewFlipper } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { // "Right Swipe" vf.showNext(); } return false; } </code></pre> <hr> <p>and this is the whole code</p> <p>ViewFlipperActivity class</p> <pre><code>import android.os.Bundle; import android.app.Activity; import android.view.GestureDetector; import android.view.GestureDetector.OnGestureListener; import android.view.View.OnTouchListener; import android.view.MotionEvent; import android.view.View; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.HorizontalScrollView; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; import android.widget.ViewFlipper; public class ViewFlipperActivity extends Activity implements OnGestureListener, OnTouchListener, GestureDetector.OnDoubleTapListener { TextView tv; GestureDetector gd; ScrollView sv; ViewFlipper vf; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gd = new GestureDetector(this); setContentView(R.layout.activity_viewflipper); tv = (TextView)findViewById(R.id.textView1); sv = (ScrollView)findViewById(R.id.scrollView1); vf = (ViewFlipper)findViewById(R.id.viewFlipper1); sv.setOnTouchListener(this); } @Override public boolean onDoubleTap(MotionEvent arg0) { tv.setText("double tap"); return false; } @Override public boolean onDoubleTapEvent(MotionEvent arg0) { tv.setText("double tap event"); return false; } @Override public boolean onSingleTapConfirmed(MotionEvent arg0) { tv.setText("single tap confirm"); return false; } @Override public boolean onTouchEvent(MotionEvent me) { return gd.onTouchEvent(me); } @Override public boolean onDown(MotionEvent arg0) { tv.setText("down"); return false; } private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_THRESHOLD_VELOCITY = 200; @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if(e1.getX() - e2.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { tv.setText("Left Swipe"); vf.showPrevious(); } else if (e2.getX() - e1.getX() &gt; SWIPE_MIN_DISTANCE &amp;&amp; Math.abs(velocityX) &gt; SWIPE_THRESHOLD_VELOCITY) { tv.setText("Right Swipe"); vf.showNext(); } return false; } @Override public void onLongPress(MotionEvent arg0) { tv.setText("long press"); } @Override public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { tv.setText("scroll"); return false; } @Override public void onShowPress(MotionEvent arg0) { tv.setText("show press"); } @Override public boolean onSingleTapUp(MotionEvent arg0) { tv.setText("single tab up"); return false; } @Override public boolean onTouch(View v, MotionEvent event) { onTouchEvent(event); return false; } } </code></pre> <p>and activity_viewflipper.xml</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="TextView" /&gt; &lt;ViewFlipper android:id="@+id/viewFlipper1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_below="@+id/textView1" &gt; &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/textView3" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="28dp" android:layout_marginTop="63dp" android:layout_toLeftOf="@+id/textView2" &gt; &lt;ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="matrix" android:src="@drawable/thailandmap" /&gt; &lt;/ScrollView&gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignTop="@+id/scrollView1" android:layout_marginRight="30dp" android:text="TextView" /&gt; &lt;TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignRight="@+id/scrollView1" android:layout_marginBottom="250dp" android:layout_marginRight="29dp" android:text="TextView" /&gt; &lt;/RelativeLayout&gt; &lt;ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:scaleType="matrix" android:src="@drawable/thwriting" /&gt; &lt;/ViewFlipper&gt; &lt;/RelativeLayout&gt; </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