16

我有一个 SlidingDrawer 从屏幕底部弹出并填充屏幕约 80%。即使 SlidingDrawer 视图处于焦点位置,仍然可以单击位于 SlidingDrawer 后面的视图中的项目、按钮和其他元素。当 SlidingDrawer 处于活动状态/上拉/聚焦时,我想禁用它后面的整个视图,这样它就无法接收点击和触摸。有没有禁用整个视图的好方法?我试过 setEnable(false) 和 setClickable(false) 但它们都不起作用。

帮助?

4

5 回答 5

13

这是解决这个问题的一种方法(我也需要一个解决方案) - 获取包含内容的 linearLayout 并添加一个点击侦听器。让点击监听器响应点击(扔掉,无论如何) - 然后阻止它传播到滑动抽屉下方的视图 - 它对我有用 - 它不会阻止抽屉中的其他项目。

于 2010-09-24T14:26:58.800 回答
3

在侧面布局做 android:clickable="true"

例如以下文件是drawer.xml

里面LinearLayout android:id="@+id/drawer_view" clickable="true"

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">


        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </FrameLayout>      

        <LinearLayout
            android:id="@+id/drawer_view"
            android:layout_width="@dimen/navigation_drawer_width"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:layout_gravity="start"
            android:clickable="true"
            android:background="@color/drawer_background">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:background="@drawable/order_list_selector"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="@dimen/user_image_w_h"
                    android:layout_height="@dimen/user_image_w_h"
                    android:scaleType="fitCenter"
                    android:id="@+id/drawerUserImage"
                    android:src="@drawable/ic_user_icon"
                    android:layout_gravity="center_vertical" />

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:layout_gravity="center_vertical"
                    android:orientation="vertical"
                    android:layout_marginLeft="5dp"
                    android:padding="5dp">

                    <TextView
                        android:id="@+id/drawerUserNameTextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Mansukh Ahir"
                        android:textColor="@android:color/black"
                        android:textSize="@dimen/font_large" />

                    <TextView
                        android:id="@+id/drawerEmailIdTextView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="@dimen/font_very_small"/>
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="fill_parent"
                android:layout_height="1dp"
                android:background="@color/holo_gray_light" />

            <ListView
                android:id="@+id/drawerListSlideMenu"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:choiceMode="singleChoice"
                android:dividerHeight="1dp" />
        </LinearLayout>

    </android.support.v4.widget.DrawerLayout>
于 2015-07-23T12:24:42.630 回答
2

乔的回答对我没有用。我的情况有点不同。我有一个有两个孩子的 FrameLayout。在给定时刻,只有一个孩子必须处于“活跃”状态,而当第二个孩子处于活跃状态时,第一个孩子不应再处理任何输入。我的解决方案:

    public static void changeVGstate(ViewGroup current, boolean enable)
{
    current.setFocusable(enable);
    current.setClickable(enable);
    current.setEnabled(enable);

    for (int i = 0; i < current.getChildCount(); i++)
    {
        View v = current.getChildAt(i); 
        if (v instanceof ViewGroup)
            changeVGstate((ViewGroup)v, enable);
        else
        {
            v.setFocusable(enable);
            v.setClickable(enable);
            v.setEnabled(enable);
        }
    }
}

享受!

于 2011-08-19T17:37:19.590 回答
2

我试图放入SlidingDrawer,RelativeLayout而不是LinearLayout. 并设置 mySlidingDrawer.bringToFront()在打开方法中。

所以我认为这可能是一个解决方案。

于 2011-10-08T19:09:51.107 回答
0

我不知道这是否可行,但值得一试。在您的容器视图(滑动抽屉滑过的那个)上调用 setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS )。

于 2010-04-07T23:40:54.590 回答