解决ScrollView与ViewPage滑动冲突的问题
生活随笔
收集整理的這篇文章主要介紹了
解决ScrollView与ViewPage滑动冲突的问题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
<?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>
時(shí)間的分發(fā)機(jī)制:首先會(huì)把觸摸事件傳給最外層的LinearLayout,然后在依次往下傳給MyScrollerView(他是繼承ScrollerView)然后在傳給RelativeLayout然后才傳給ViewPage,所有在傳遞的時(shí)候會(huì)出現(xiàn)MyScrollerView與Viewpage的滑動(dòng)沖突。
解決方法:1、自定義一個(gè)類繼承與ScrollerView
????????????????2、重寫(xiě)這個(gè)類的onIterceptTouchEvent()方法
????????????????3、在方法中通過(guò)判斷手勢(shì)是橫向的還是豎直的
????????????????4、如果是橫向的(既是Viewpage的滑動(dòng)事件),就return false:代表自己本身不處理這個(gè)事件,交給下一級(jí)處理。
下面是代碼:
==(MotionEvent?ev)?{(ev.getAction()){MotionEvent.:=?ev.getX()=?ev.getY()MotionEvent.:+=?Math.(-ev.getX())+=?Math.(-ev.getY())=?ev.getX()=?ev.getY()(>){}}.onInterceptTouchEvent(ev)}轉(zhuǎn)載于:https://my.oschina.net/u/2485622/blog/601123
《新程序員》:云原生和全面數(shù)字化實(shí)踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的解决ScrollView与ViewPage滑动冲突的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 海西数据获评优秀服务器租用服务商奖项
- 下一篇: myeclipse转maven项目