<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<com.blackdog.baiduui.view.MyScrollerView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.blackdog.baiduui.view.MyAdScoll
android:id="@+id/myAdScoll"
android:layout_width="match_parent"
android:layout_height="300dp"/>
</RelativeLayout>
</com.blackdog.baiduui.view.MyScrollerView>
</LinearLayout>
时间的分发机制:首先会把触摸事件传给最外层的LinearLayout,而后在依次往下传给MyScrollerView(他是继承ScrollerView)而后在传给RelativeLayout而后才传给ViewPage,全部在传递的时候会出现MyScrollerView与Viewpage的滑动冲突。android
解决方法:一、自定义一个类继承与ScrollerViewui
二、重写这个类的onIterceptTouchEvent()方法spa
三、在方法中经过判断手势是横向的仍是竖直的code
四、若是是横向的(既是Viewpage的滑动事件),就return false:表明本身自己不处理这个事件,交给下一级处理。xml
下面是代码:继承
==(MotionEvent ev) { (ev.getAction()){ MotionEvent.: = ev.getX()= ev.getY()MotionEvent.: += Math.(-ev.getX())+= Math.(-ev.getY())= ev.getX()= ev.getY()(>){ } } .onInterceptTouchEvent(ev)}