Rectangle 27 18

I would suggest you have a look at the Google I/O 2010 app source code, as their FlingableTabHost implementation would appear to have solved this problem:

I think the key is in extending TabHost and overriding its onInterceptTouchEvent method.

I implemented the gesture detection in my Tabs class which extends TabActivity though. Should I put the handling in another class entirely which then extends TabHost? I am not really sure how to go about implementing it (lacking overview), heh.

Why not implement it exactly as they have done in that project? You should be able to copy their FlingableTabHost inner class definition into your TabActivity class. Just make sure you use a custom layout for the content view that references your custom FlingableTabHost view instead of the normal TabHost, like in: code.google.com/p/iosched/source/browse/trunk/res/layout/

Hoorah, I got it to work with some major work-arounds. Implementing Google's FlingableTabHost made it work with the Activities where I have ScrollViews, but stopped it working on some other parts. So I reenabled my onTouchEvent-listener and now it works on both. It's not pretty, but it works. :) Thanks a lot, Jeff. I may want to re-implement my application at some point with a focus on a View-based application (so I'm not constantly jumping between Activities), it shouldn't complicate much in terms of the code I use for this, right? By the way, have some +rep and a claimed bounty.

android - Swipe/Fling tab-changing in conjunction with ScrollView? - S...

android scrollview swipe
Rectangle 27 1

You need to add the following code into your Activity. With this code, the Activity gives the GestureDetector a chance to see the touch event.

@Override
public boolean dispatchTouchEvent(MotionEvent ev){
    super.dispatchTouchEvent(ev);
    return gDetector.onTouchEvent(ev);
}

EDIT: You said you wanted an example of this working with LinearLayout.

package com.brianattwell.app;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnGestureListener {
    GestureDetector gDetector;TextView tv;
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
    private static final int SWIPE_THRESHOLD = 100;
    private static final int SWIPE_VELOCITY_THRESHOLD = 100;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gDetector = new GestureDetector(this);
        tv=(TextView)findViewById(R.id.tv);

    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev){
        super.dispatchTouchEvent(ev);
        return gDetector.onTouchEvent(ev);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        //getMenuInflater().inflate(R.menu., menu);
        return true;
    }

    @Override
    public boolean onDown(MotionEvent arg0) {
        // TODO Auto-generated method stub
        Log.d("onDown","In OnDown");
        return true;

    }

    public void rightToLeft() {

        //tv.setText("There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value.");
        tv.setText("ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssALGIERS (Reuters) - Algerian President Abdelaziz Bouteflika, who suffered a stroke last year, has been in a Paris hospital since Monday for a long-planned check-up and he is making steady progress, the state news agency APS said on Tuesday.Algerians vote for a new president in April. Bouteflika, 76, has yet to announce whether he will run again after more than 10 years at the helm of the major North African oil producer.To complete his health assessment, started in Algiers, and under a routine medical control ... planned since June 2013, the President of the Republic Abdelaziz Bouteflika is staying at Val-de-Grace hospital, it said. The president's health is improving certainly and progressively.APS, citing a presidential statement, said Bouteflika would remain at the hospital until Friday.A veteran of Algeria's independence war against France, Bouteflika suffered a stroke in early 2013, forcing him to be rushed to hospital in France. He returned to Algeria in July to convalesce and has made only a few public appearances recentlsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssALGIERS (Reuters) - Algerian President Abdelaziz Bouteflika, who suffered a stroke last year, has been in a Paris hospital since Monday for a long-planned check-up and he is making steady progress, the state news agency APS said on Tuesday.Algerians vote for a new president in April. Bouteflika, 76, has yet to announce whether he will run again after more than 10 years at the helm of the major North African oil producer.To complete his health assessment, started in Algiers, and under a routine medical control ... planned since June 2013, the President of the Republic Abdelaziz Bouteflika is staying at Val-de-Grace hospital, it said. The president's health is improving certainly and progressively.APS, citing a presidential statement, said Bouteflika would remain at the hospital until Friday.A veteran of Algeria's independence war against France, Bouteflika suffered a stroke in early 2013, forcing him to be rushed to hospital in France. He returned to Algeria in July to convalesce and has made only a few public appearances recentlsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssALGIERS (Reuters) - Algerian President Abdelaziz Bouteflika, who suffered a stroke last year, has been in a Paris hospital since Monday for a long-planned check-up and he is making steady progress, the state news agency APS said on Tuesday.Algerians vote for a new president in April. Bouteflika, 76, has yet to announce whether he will run again after more than 10 years at the helm of the major North African oil producer.To complete his health assessment, started in Algiers, and under a routine medical control ... planned since June 2013, the President of the Republic Abdelaziz Bouteflika is staying at Val-de-Grace hospital, it said. The president's health is improving certainly and progressively.APS, citing a presidential statement, said Bouteflika would remain at the hospital until Friday.A veteran of Algeria's independence war against France, Bouteflika suffered a stroke in early 2013, forcing him to be rushed to hospital in France. He returned to Algeria in July to convalesce and has made only a few public appearances recently.");
    }
    public void lefttoRight() {
        tv.setText("leftToRight LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes for a list of all child view attributes that this class supportsght LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes for a list of all child view attributes that this class supportsght LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes for a list of all child view attributes that this class supports. ");
    }

    @Override
    public boolean onFling(MotionEvent start, MotionEvent finish, float velocityX,
                           float velocityY) {
        // TODO Auto-generated method stub
        //TextView t=(TextView)findViewById(R.id.tv);
        /*if(start.getRawX() < finish.getRawX())
        {
            Log.d("onFling","in inFling");
        }
        else if(start.getRawX()>finish.getRawX())
        {
            Log.d("onFLing","in onFling");
        }*/
        if (Math.abs(start.getY() - finish.getY()) > SWIPE_MAX_OFF_PATH)
            return false;
        // right to left swipe

        if(start.getX() - finish.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

            lefttoRight();

        }
        else if (finish.getX() - start.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
            rightToLeft();
        }
        return true;
    }


    @Override
    public boolean onTouchEvent(MotionEvent me) {
        return gDetector.onTouchEvent(me);
    }

    @Override
    public void onLongPress(MotionEvent arg0) {
        // TODO Auto-generated method stub
        Log.d("onLongPress","in onlongpress");
    }



    @Override
    public void onShowPress(MotionEvent arg0) {
        // TODO Auto-generated method stub
        Log.d("onShowPress","in onShowPress");

    }

    @Override
    public boolean onSingleTapUp(MotionEvent arg0) {
        // TODO Auto-generated method stub
        Log.d("onSingleTapup","in onsingletapup");
        return true;
    }

    @Override
    public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
                            float arg3) {
        // TODO Auto-generated method stub
        return false;
    }

}
<LinearLayout 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"
    tools:context=".Gestures" >



    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello_world" />

    </ScrollView>

</LinearLayout>

Sorry, I misread your comment. I don't think it should make a difference. Let me check.

Thanks It worked for Activity but I implemented TouchListener in a class(OnSwipeTouchListener).I tried to add the TouchListener to linearlayout(OnSwipeTouchListener swp=new OnSwipeTouchListener(); gestureDetector = new GestureDetector(swp.new GestureListener());linearLayout.setOnTouchListener(swp); There Scrolling is not working.Please help me.

I just pasted a modification of your code that works, with a LinearLayout.

The swipe should work for part of the screen so I took a linearlayout inside ScrollView and added the TouchListener to linearlayout.Could you please provide your mail id.I will post the code.

Impementing Vertical Scroll with horizontal swipe in Android - Stack O...

android vertical-scrolling swipe-gesture
Rectangle 27 1

First: Saying that TouchWIZ does not support ACTION_SCROLL_FORWARD and ACTION_SCROLL_BACKWORD is like saying a text view doesn't support ACTION_CLICK. The two actions you refer to only apply to scrollable content within a ScrollView. TouchWIZ uses paging. Meaning, you're not "scrolling" you are swiping in a new view. While the action appears to be scrolling, it is actually paging across. From a conceptual point of view these are the same thing, however, "scrolling" in this sense has a very formal definition within the Android APIs.

The TouchWIZ developers could implement listeners for these, so that on scroll events, paging occurs, but that would have to happen within the application.

They could also define the ordering of focusable elements to be such that, paging occurs automatically. Though, again, this is an application side solution, and not one a service an enforce. Though, I believe they do this, IF you're using a keyboard tab key to navigate, and not arrow keys, or gesture navigation.

Second: When you request touch exploration mode, from an accessibility service, two finger gestures will get passed through as one finger gestures. So, it is fairly easy to page through the TouchWIZ with the default behavior of touch exploration mode, and is what AT users would be use to.

Third: I believe what you're hinting at is a feature that Google has been working on for some time and that is the ability to pass, from an accessibility service, true hardware gestures. So that a service could create true swipe gestures, from simpler gestures, on the users behalf. This, I don't believe is fully implemented yet. I had thought, from their CSUN presentation in 2016, that it would be available in Android 6, but perhaps it got pushed back to 7 or even 7.1. When this feature is available, I believe it is the solution you are looking for. Until it is available there is no direct way to accomplish what you want.

TouchWiz not support scroll/swipe using Android Accessibility - Stack ...

android accessibility accessibilityservice samsung-touchwiz
Rectangle 27 0

For what it's worth, I found the onFling method very unreliable. I override the onScroll method in the SimpleGestureDetector, and define my onInterceptTouchEvent as:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    //Call super first because it does some hidden motion event handling
    boolean result = super.onInterceptTouchEvent(ev);
    if (this.mGestureScanner.onTouchEvent(ev)) return true;
    return result;
}

android - Swipe/Fling tab-changing in conjunction with ScrollView? - S...

android scrollview swipe
Rectangle 27 0

If your menu is in a fragment you can add it to the back stack.

Then when you press back it will go back to the previous menu before exiting (on another back button press)

how to go back to the previous menu on pressing the back button? - And...

android android-activity scrollview swipe
Rectangle 27 0

You could extend your own vertical scrollview that does not trigger the event for a horizontal swipe. Of course, then you would have to swipe on a part that is not the scroll view.

--Extra Comment ---Have you tested this on various phones/devices? You may find yourself having different results.

Ideally I would like the whole screen to be swipeable, but only in the horizontal plane. No I have only tested on emulators so far.

I'd suggest trying it on an actual phone if possible (may borrow a friends?) and seeing if you have the same results. The emulator has come a long way, but if you have a slower computer, its results can be rather wonky/awkward I've found.

java - Android Developemnt: Decrease horizontal swipe sensitivity OR t...

java android swipe
Rectangle 27 0

I've found a solution for this issue. While I was unable to forward the swipe up/down gestures to the image views behind the scrollview, I've now added gesture recognisers with direction up/down to the scrollview. In the gesture recognisers actions, I determine the point of the gesture within the window and hittest the window's first view for these point with a nil event. In the custom scrollview, I overwrote the hittest message to return NO with an empty event so the appropriate imageview would eventually be identifier. Once I got the imageview lying behind the scrollview at the point of the gesture, I was able to perform the appropriate action on my imageview.

I'm not sure whether this is the finest solution for this issue, however I wasn't able to build a better one after hours of investigation and experimenting. This setup might be a bit unusual and therefor tricky. Your input is still appreciated in case you have anything to add.

objective c - Forward/pass through UIGesture (swipe) to sibling view -...

objective-c uiscrollview uigesturerecognizer uitouch uiswipegesturerecognizer
Rectangle 27 0

eventsInterceptionEnabled: when set to true, this property tells the overlay to steal the events from its children as soon as it knows the user is really drawing a gesture. This is useful when there's a scrollable view under the overlay, to avoid scrolling the underlying child as the user draws his gesture

<android.gesture.GestureOverlayView>

As Jeff suggested, I just went with the way Google had solved it in the ScheduleActivity (and .xml) linked. It's not the prettiest solution as I'm listening on 2 things at the same time, but it works great to ensure that scrolling & swiping work flawlessly. :)

android - Swipe/Fling tab-changing in conjunction with ScrollView? - S...

android scrollview swipe
Rectangle 27 0

Create a custom ScrollView by extending it and implement dispatchTouchEvent.

We start tracking the touch ( with the pixel positions on sceen ) in ACTION_DOWN. When we see that it's a horizontal swipe, we do not call super.dispatchTouchEvent( event ) - which would do the default onTouch routing and make certain child views consume the horizontal swipe too - but call onTouchEvent( event ) instead in ACTION_MOVE and also in ACTION_UP.

public class MyScrollView extends ScrollView {

    private float mLastX;
    private float mLastY;
    private final int mTouchSlop = ViewConfiguration.get( getContext() ).getScaledTouchSlop();
    private float mStartX;

    public ScrollView( Context context ) {
        super( context );
    }

    public ScrollView( Context context, AttributeSet attrs ) {
        super( context, attrs );
    }

  @Override
  public boolean dispatchTouchEvent( MotionEvent event ) {
    switch( event.getAction() ) {
        case MotionEvent.ACTION_DOWN:
            mLastX = event.getX();
            mLastY = event.getY();
            mStartX = event.getX();
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            onTouchEvent( event );
            break;
        case MotionEvent.ACTION_MOVE:
            float x = event.getX();
            float y = event.getY();

            float xDelta = x - mLastX;
            float xDeltaAbs = Math.abs( xDelta );
            float yDeltaAbs = Math.abs( y - mLastY );

            float xDeltaTotal = x - mStartX;
            if( Math.abs( xDeltaTotal ) > mTouchSlop )
                if( xDeltaAbs > yDeltaAbs )
                    return onTouchEvent( event );
        }

        return super.dispatchTouchEvent( event );
    }
}

I only tried this with ViewPager instead of a ScrollVIew, but in this same situation so this should work

touch - Vertical Scroll along with Horizontal Swipe in Android - Stack...

android touch scrollview
Rectangle 27 0

On your LinearLayout, in your XML. Set android:weightSum="2". For each viewpager, set android:layout_weight="1". Also, set the height of each child of the LinearLayout to 0dp. That should do the trick

The weightSum=2 and each layout_weight=1 didn't do the trick. When I set height of each child to 0dp they doesn't appaer at all.

Actually it was an error in the MainActivity. Used setAdapter on a wrong ViewPager :) Thanks for the tip with weightSum anyway!

@KiberNet: Hi I to have the same issue. and i am setting the adopter properly. and trying with wgightsum also. no progress. and in fact if i ViewPagers in Scrollview just like you did view pager itself not displayed. please help me if you have any idea.

android - How to get several ViewPagers into a ScrollView? - Stack Ove...

android scrollview swipe android-viewpager
Rectangle 27 0

You can check out this example for implementing pull to refresh in ListView, GridView, WebView, Expandable ListView.

onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event){ 

    int action = MotionEventCompat.getActionMasked(event);

    switch(action) {
        case (MotionEvent.ACTION_DOWN) :
            Log.d(DEBUG_TAG,"Action was DOWN");
            return true;
        case (MotionEvent.ACTION_MOVE) :
            Log.d(DEBUG_TAG,"Action was MOVE");
            return true;
        case (MotionEvent.ACTION_UP) :
            Log.d(DEBUG_TAG,"Action was UP");
            return true;
        case (MotionEvent.ACTION_CANCEL) :
            Log.d(DEBUG_TAG,"Action was CANCEL");
            return true;
        case (MotionEvent.ACTION_OUTSIDE) :
            Log.d(DEBUG_TAG,"Movement occurred outside bounds " +
                    "of current screen element");
            return true;      
        default : 
            return super.onTouchEvent(event);
    }      
}
MotionEvent.ACTION_UP

Android's ScrollView with Custom Swipe Events - Stack Overflow

android scrollview swipe gesture
Rectangle 27 0

The issue is related to by default height of ViewPager as by default it is taking "fill_parent" , which we are not able to reset with "wrap_content". The solution which i found that fixing the height to some hard code value will return you all the view pager item appear in your screen.

I know this is some fishy solution but it works fine for me and i hope it should work with you.

android - How to get several ViewPagers into a ScrollView? - Stack Ove...

android scrollview swipe android-viewpager
Rectangle 27 0

This answer by Marek Sebera is very easy and fast to implement, and allows you to set the swipe listener to only the child you want to set it to and have the function replace the views when it's detected.

Upvote for speed and accuracy. Will mark it as correct after I've taken a look and got it working for myself. Thanks man! :)

The answer only lets me detect which way is being swiped. It does not go into detail on how to actually move certain viewgroups inside a relative layout. Do you have any idea on how that is handled?

Do you want it to move as you drag it? This answer doesn't include animation as you drag it - although you could program your own animation after the swipe is detected. Or are you saying you're not sure how to replace the views in the relativelayout with the new viewgroup?

android - Swipe single viewgroup in Relative layout containg multiple ...

android android-viewpager scrollview swipe
Rectangle 27 0

Using ViewPager would be a solution.

java - FragmentTabHost Horizontal Scrollview + Swipe Android - Stack O...

java android android-layout android-fragments android-tabs
Rectangle 27 0

I've found a solution for this issue. While I was unable to forward the swipe up/down gestures to the image views behind the scrollview, I've now added gesture recognisers with direction up/down to the scrollview. In the gesture recognisers actions, I determine the point of the gesture within the window and hittest the window's first view for these point with a nil event. In the custom scrollview, I overwrote the hittest message to return NO with an empty event so the appropriate imageview would eventually be identifier. Once I got the imageview lying behind the scrollview at the point of the gesture, I was able to perform the appropriate action on my imageview.

I'm not sure whether this is the finest solution for this issue, however I wasn't able to build a better one after hours of investigation and experimenting. This setup might be a bit unusual and therefor tricky. Your input is still appreciated in case you have anything to add.

objective c - Forward/pass through UIGesture (swipe) to sibling view -...

objective-c uiscrollview uigesturerecognizer uitouch uiswipegesturerecognizer
Rectangle 27 0

You just need to comment out e.stopPropagation() in _handleDragStart function() to stop bubbling the parent events, like the JQM swipe events in your case.

OR you can disable according to condition, e.g., for vertical scrollbars, if you want to have swipeLeft and swipeRight events, use this

( this.options.direction == "y" ) ? "" : e.stopPropagation();

jQuery Mobile swipe events not fire when using scrollview plugin - Sta...

jquery-mobile scrollview swipe