解決ScrollView與ViewPage滑動衝突的問題

<?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)}
相關文章
相關標籤/搜索