ViewPager如何阻止其滑動和一次切換多頁閃爍的問題
阿新 • • 發佈:2019-01-02
public class CustomViewPager extends ViewPager{
private boolean isCanScroll = true;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CustomViewPager(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void setCanScroll(boolean isCanScroll){
this.isCanScroll = isCanScroll;
}
@Override
public boolean onTouchEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
if(isCanScroll){
return super.onTouchEvent(arg0);
}else{
return false;
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
if(isCanScroll){
return super.onInterceptTouchEvent(arg0);
}else{
return false;
}
}
}
問題是解決,但是如果點選標籤橫切多個page頁面是,會出現閃爍,影響使用者體驗,又要改,
private boolean isCanScroll = true;
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public CustomViewPager(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public void setCanScroll(boolean isCanScroll){
this.isCanScroll = isCanScroll;
}
@Override
public boolean onTouchEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
if(isCanScroll){
return super.onTouchEvent(arg0);
}else{
return false;
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
// TODO Auto-generated method stub
if(isCanScroll){
return super.onInterceptTouchEvent(arg0);
}else{
return false;
}
}
}
問題是解決,但是如果點選標籤橫切多個page頁面是,會出現閃爍,影響使用者體驗,又要改,