33
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package cn.shangyu.gdxzExpert.view;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
/**
|
||||
* 自定义的不可左右滑动的viewpager
|
||||
* @author gaopeng
|
||||
*
|
||||
*/
|
||||
public class IndexViewPager extends ViewPager {
|
||||
|
||||
private boolean isCanScroll = false;
|
||||
|
||||
public IndexViewPager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public IndexViewPager(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public void setScanScroll(boolean isCanScroll) {
|
||||
this.isCanScroll = isCanScroll;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void scrollTo(int x, int y) {
|
||||
super.scrollTo(x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
if (isCanScroll) {
|
||||
return super.onTouchEvent(arg0);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item, boolean smoothScroll) {
|
||||
// TODO Auto-generated method stub
|
||||
super.setCurrentItem(item, smoothScroll);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentItem(int item) {
|
||||
// TODO Auto-generated method stub
|
||||
super.setCurrentItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(MotionEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
if (isCanScroll) {
|
||||
return super.onInterceptTouchEvent(arg0);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user