备忘-Android ViewPager 与Gallery滑动冲突解决方法

解决方法,重新定义gallery,禁止触发pager的触摸事件

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
1 public class UserGallery extends Gallery implements OnGestureListener {
 2         ViewPager mPager;
 3         
 4         public ViewPager getmPager() {
 5                 return mPager;
 6         }
 7 
 8         public void setmPager(ViewPager mPager) {
 9                 this.mPager = mPager;
10         }
11 
12         /**
13          * @param context
14          * @param attrs
15          */
16         public UserGallery(Context context) {
17                 super(context);
18                 // TODO Auto-generated constructor stub
19         }
20 
21         /**
22          * @param context
23          * @param attrs
24          */
25         public UserGallery(Context context, AttributeSet attrs) {
26                 super(context, attrs);
27                 // TODO Auto-generated constructor stub
28         }
29         
30         @Override
31         public boolean dispatchTouchEvent(MotionEvent ev) {
32                 // TODO Auto-generated method stub
33                 mPager.requestDisallowInterceptTouchEvent(true);
34                 return super.dispatchTouchEvent(ev);
35         }
36 
37         @Override
38         public boolean onInterceptTouchEvent(MotionEvent ev) {
39                 // TODO Auto-generated method stub
40                 mPager.requestDisallowInterceptTouchEvent(true);
41                 return super.onInterceptTouchEvent(ev);
42         }
43 
44         @Override
45         public boolean onTouchEvent(MotionEvent event) {
46                 // TODO Auto-generated method stub
47                 mPager.requestDisallowInterceptTouchEvent(true);
48                 return super.onTouchEvent(event);
49         }
50 
51 }

这里注意xml中的使用方法  

<com.example.UserGallery
android:layout_width="fill_parent"
android:layout_height="100dp"
android:id="@+id/GalleryView"

/>

备忘-Android ViewPager 与Gallery滑动冲突解决方法,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。