码迷,mamicode.com
首页 > 其他好文 > 详细

viewpager禁止滑动

时间:2016-06-24 12:41:45      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:

package com.ofess.lottery.lottery.view;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
* Created by gateway on 2016/6/24.
*/
public class MyViewPager extends ViewPager {




private boolean isCanScroll = false;

public MyViewPager(Context context) {
super(context);
}

public MyViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}



//默认不能滑动,设置为true时能滑动

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;
}

}


}

 

<YourPackeageName.IndexViewPager
        android:id="@+id/vPager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="1.0"
        android:background="#000000"
        android:flipInterval="30"
        android:persistentDrawingCache="animation" />


引用自http://www.cnblogs.com/longhs/p/4173688.html

 

viewpager禁止滑动

标签:

原文地址:http://www.cnblogs.com/gaoliangjie/p/5613376.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!