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页面是,会出现闪烁,影响用户体验,又要改,
Set the currently selected page.
Parameters
item | Item index to select |
---|---|
smoothScroll | True to smoothly scroll to the new item, false to transition immediately 返回true弹性滑动到新的item,false 立刻滑动到item |
@Override
public void setCurrentItem(int item, boolean smoothScroll) {
super.setCurrentItem(item, smoothScroll);
}
@Override
public void setCurrentItem(int item) {
super.setCurrentItem(item, false);
}
其中,super.setCurrentItem(item, false);,表示切换的时候,不需要切换时间。
问题解决了还是很欣慰的!
http://blog.csdn.net/eclipsexys/article/details/49758155 关于viewpager切换的控制 医生写的 实验了 居然没用 是哪里不对呢? // @Override // protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) { // boolean rt = super.canScroll(v, checkV, dx, x, y); // if (dx < 0 && (isCanScroll/*其他逻辑控制**/)) { // return true; // } // return rt; // } // @Override // public int reDetermineTargetPage(int targetPage) { // int rtn = targetPage; // int currentPage = getCurrentItem(); // if (targetPage > currentPage && (isCanScroll/* 其他逻辑控制**/)) { // rtn = currentPage; // } // return rtn; // }