D
D
Dmitry Serkov2016-08-06 09:23:39
Android
Dmitry Serkov, 2016-08-06 09:23:39

Is it possible to disable swipe in fragments?

Hello.
Is it possible to disable swipe in fragments?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Serkov, 2016-08-25
@Hutaab

We write our ViewPager:

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class NoSwipeViewPager extends ViewPager{
    private boolean swipeable;

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

    public NoSwipeViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.swipeable = true;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (this.swipeable) {
            return super.onTouchEvent(event);
        }

        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (this.swipeable) {
            return super.onInterceptTouchEvent(event);
        }

        return false;
    }

    public void setSwipeable(boolean swipeable) {
        this.swipeable = swipeable;
    }
}

Add to markup:
<com.example......NoSwipeViewPager
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"  />

Disable Swipe in Activity:
private NoSwipeViewPager mViewPager;
        ..............
        mViewPager = (NoSwipeViewPager) findViewById(R.id.container);
        mViewPager.setSwipeable(false);

S
semenir986, 2016-08-18
@semenir986

I think you can, you need to look in the settings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question