java - 怎样在不重写子布局的情况下,屏蔽侧滑菜单中的内容布局事件?
伊谢尔伦
伊谢尔伦 2017-04-18 10:54:04
0
1
511

我自己对之前的android自定义viewgroup做一个总结,手写一个控件继承viewgroup,采用scroller类实现一个自定义侧滑菜单。疑惑的是,当侧滑菜单展示时,内容布局应当屏蔽事件,但是目前我只知道通过重写内容布局的onInterceptTouchEvent方法返回true做到,但是我考虑到简易化,能否在只手写一个viewgroup情况下,实现这种需求?

<?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">

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#69c"
        android:orientation="horizontal">
        
    </LinearLayout>

    <LinearLayout
        android:id="@+id/menu"
        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代替是可行的,但是这样我就觉得约束性太强,最终目的是要只要菜单有滑动,点击内容布局就会隐藏menu。有没有大神提提醒,我也研究过requestDisallowInterceptTouchEvent,貌似这个主要针对子view对父布局的,已经自我钻研好多天了,知道的帮忙看看,谢了~~

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
刘奇

I don’t know exactly how you implement this, so it’s hard to say how to handle this sliding event, but we may be able to achieve the goal in another way:
Try to add a full-screen, transparent parentView to the menu and use it to intercept And handle click events outside the menu view.
Hope it can help you.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!