ホームページ  >  に質問  >  本文

java - 怎样在不重写子布局的情况下,屏蔽侧滑菜单中的内容布局事件?

我自己对之前的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对父布局的,已经自我钻研好多天了,知道的帮忙看看,谢了~~

伊谢尔伦伊谢尔伦2743日前508

全員に返信(1)返信します

  • 怪我咯

    怪我咯2017-04-18 10:56:04

    これをどのように実装しているのか正確にはわからないので、このスライディング イベントを処理する方法を言うのは難しいですが、別の方法で目標を達成できるかもしれません:
    全画面の透明なparentViewをメニューを作成し、それを使用してメニュー ビュー外のクリック イベントをインターセプトおよび処理します。
    お役に立てれば幸いです。

    返事
    0
  • キャンセル返事