NoScrollViewPager.java
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.xdy.ui.viewgroup;
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
/**
* @author jianghongbo
* @version 1.0
* @file NoScrollViewPager.java
* @brief
* @date 2017/3/25
* Copyright (c) 2017, 学点云
* All rights reserved.
*/
public class NoScrollViewPager extends ViewPager {
private boolean isPagingEnabled = true;
public NoScrollViewPager(Context context) {
super(context);
}
public NoScrollViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return this.isPagingEnabled && super.onInterceptTouchEvent(event);
}
public void setPagingEnabled(boolean b) {
this.isPagingEnabled = b;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (listener != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
listener.onClick();
}
return super.dispatchTouchEvent(ev);
}
private OnRplayTouchListener listener;
public interface OnRplayTouchListener {
public void onClick();
}
public void setOnRplayTouchListener(OnRplayTouchListener listener) {
this.listener = listener;
}
}