SoFunction
Updated on 2025-03-11

Android viewpage implements the function of prohibiting sliding

Android viewpage implements no swipe

Since there is an Android viewpage that implements a function that prohibits sliding when working on a project recently, I initially feel that it is difficult to implement, but the tasks assigned by the project manager and customer needs have been made with a gritty slogan. Here is a record of how to implement them.

The method is very simple

              Just rewrite the viewpager, and now post the code.

import ;
import .;
import ;
import ;


public class CustomViewPager extends ViewPager {


  private boolean enabled;


  public CustomViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
     = false;
  }

Just touch without response

  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if () {
      return (event);
    }
 
    return false;
  }


  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    if () {
      return (event);
    }
 
    return false;
  }
 
  public void setPagingEnabled(boolean enabled) {
     = enabled;
  }
}



Then inherit this class

Thank you for reading, I hope it can help you. Thank you for your support for this site!