java - 怎樣在不重寫子布局的情況下,屏蔽側(cè)滑菜單中的內(nèi)容布局事件?
問題描述
我自己對(duì)之前的android自定義viewgroup做一個(gè)總結(jié),手寫一個(gè)控件繼承viewgroup,采用scroller類實(shí)現(xiàn)一個(gè)自定義側(cè)滑菜單。疑惑的是,當(dāng)側(cè)滑菜單展示時(shí),內(nèi)容布局應(yīng)當(dāng)屏蔽事件,但是目前我只知道通過(guò)重寫內(nèi)容布局的onInterceptTouchEvent方法返回true做到,但是我考慮到簡(jiǎn)易化,能否在只手寫一個(gè)viewgroup情況下,實(shí)現(xiàn)這種需求?
<?xml version='1.0' encoding='utf-8'?><com.example.caojiantao1.myapplication.SlidingMenu xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' xmlns:slide='http://schemas.android.com/apk/res-auto' slide:content_alpha='0.5' slide:menu_width_rate='0.6' slide:scale_rate='0.5' slide:sliding_mode='qq'> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:background='#69c'android:orientation='horizontal'> </LinearLayout> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='match_parent'android:background='#fc6'android:orientation='horizontal'> </LinearLayout></com.example.caojiantao1.myapplication.SlidingMenu>
如果直接重寫content布局,在onInterceptTouchEvent down中判斷返回true,然后用com.xxx.cotent代替是可行的,但是這樣我就覺得約束性太強(qiáng),最終目的是要只要菜單有滑動(dòng),點(diǎn)擊內(nèi)容布局就會(huì)隱藏menu。有沒有大神提提醒,我也研究過(guò)requestDisallowInterceptTouchEvent,貌似這個(gè)主要針對(duì)子view對(duì)父布局的,已經(jīng)自我鉆研好多天了,知道的幫忙看看,謝了~~
問題解答
回答1:不清楚你這個(gè)具體是怎么實(shí)現(xiàn)的,所以也不好說(shuō)這個(gè)滑動(dòng)事件的處理,不過(guò)我們或許可以用另一種方式達(dá)成目的:嘗試為menu添加一個(gè)全屏的、透明的parentView,并利用它攔截與處理menu view之外的點(diǎn)擊事件.希望能幫到你。
