0

经过一些尝试,当我单击浮动按钮时,我能够生成半透明背景。现在的问题是“新背景”只会改变颜色。在此之下,我有一个回收视图,我仍然可以向上或向下滑动并与之交互。我现在需要的是在我可见的布局下使用 recyclerview 防止所有操作。我唯一能做的就是:

  • 如果我单击半透明视图,则工厂崩溃

这是实际使用的代码:

OnClickListener listener = new OnClickListener()
    {
        @Override
        public void onClick(View v)
        {
            if (DrawerActivity.instance.rootFab.isExpanded())
            {
                whiteLayout.setVisibility(View.GONE);
            }
            else
            { 
                whiteLayout.setVisibility(View.VISIBLE);

            }
            mainFab.toggle();
        }
    };

而且当然:

rootFab.setAddButtonClickListener(listener);

给它听者。所以,简单地,点击主晶圆厂(我使用一个有多个晶圆厂的库),它会显示如下布局:

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <LinearLayout
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:orientation="vertical"
            android:visibility="gone" >
        </LinearLayout>
---
---

如果我再次按下fab,布局就会消失......所以我的问题是,我怎么能做同样的事情,但点击这个背景但没有“触摸”它的recyclerview?

4

1 回答 1

2

您可以告诉 Android 您的视图是“可点击的”。这样,您的视图将使用触摸事件,并且它们不会进一步传递给您的RecyclerView.

要将视图标记为“可点击”,只需将以下标志添加到您的 xml 布局中android:clickable="true"::

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <LinearLayout
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:orientation="vertical"
            android:clickable="true"
            android:visibility="gone" >
        </LinearLayout>
---
---

另外,如果您仅将视图用作背景-我看不出您需要重量级的任何理由LinearLayout。你可以在View这里使用:

----
----
 <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />
        <View
            android:id="@+id/semi_white_bg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_semi_transparent"
            android:clickable="true"
            android:visibility="gone" />
---
---
于 2015-03-30T22:29:14.167 回答