41 lines
953 B
Java
41 lines
953 B
Java
package com.gh.common.view;
|
|
|
|
import android.content.Context;
|
|
import android.support.v4.view.ViewPager;
|
|
import android.util.AttributeSet;
|
|
import android.view.MotionEvent;
|
|
|
|
/**
|
|
* Created by khy on 2017/2/24.
|
|
* 控制是否可以左右滑动
|
|
*/
|
|
public class NoScrollableViewPager extends ViewPager {
|
|
|
|
private boolean isScrollable;
|
|
|
|
public NoScrollableViewPager(Context context) {
|
|
super(context);
|
|
isScrollable = true;
|
|
}
|
|
|
|
public NoScrollableViewPager(Context context, AttributeSet attrs) {
|
|
super(context, attrs);
|
|
isScrollable = true;
|
|
|
|
}
|
|
|
|
@Override
|
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
|
return isScrollable && super.onInterceptTouchEvent(ev);
|
|
}
|
|
|
|
@Override
|
|
public boolean onTouchEvent(MotionEvent ev) {
|
|
return isScrollable && super.onTouchEvent(ev);
|
|
}
|
|
|
|
public void setScrollable(boolean scrollable) {
|
|
isScrollable = scrollable;
|
|
}
|
|
}
|