```
class NoScrollViewPagerNew : ViewPager {
// 是否禁止 viewpager 左右滑动
var noScroll =false
constructor(context: Context) :this(context, null)
constructor(context: Context, attrs: AttributeSet?) :super(context, attrs)
override fun onTouchEvent(ev: MotionEvent?): Boolean {
return (!noScroll) &&super.onTouchEvent(ev)
}
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return (!noScroll) &&super.onInterceptTouchEvent(ev)
}
override fun canScrollHorizontally(direction: Int): Boolean {
return if (noScroll) {
false
}else {
super.canScrollHorizontally(direction)
}
}
}
```