Java 防止触碰视图
经过一些尝试,当我点击我的浮动按钮时,我能够生成半透明的背景。现在的问题是“新背景”只会改变颜色。在这种情况下,我有一个循环视图,我仍然可以向上或向下键入,并与之交互。我现在需要的是防止在我使其可见的布局下使用recyclerview执行任何操作。我唯一能做的就是:Java 防止触碰视图,java,android,android-layout,floating-action-button,Java,Android,Android Layout,Floating Action Button,经过一些尝试,当我点击我的浮动按钮时,我能够生成半透明的背景。现在的问题是“新背景”只会改变颜色。在这种情况下,我有一个循环视图,我仍然可以向上或向下键入,并与之交互。我现在需要的是防止在我使其可见的布局下使用recyclerview执行任何操作。我唯一能做的就是: 如果我点击半透明视图,晶圆厂就会倒塌 这是实际使用的代码: OnClickListener listener = new OnClickListener() { @Override pub
- 如果我点击半透明视图,晶圆厂就会倒塌
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,布局就会消失。。。所以我的问题是,我如何做同样的事情,但在这个背景上单击,而不“触摸”回收器视图?你可以告诉Android你的视图是“可单击的”。这样,您的视图将使用触摸事件,它们不会被进一步传递到您的
RecyclerView
要将视图标记为“可点击”,只需在xml布局中添加以下标志:android:clickable=“true”
:
是的,事实上我正在用视图更新代码。对了,没错!现在我的视图被标记为可单击。我再也不能碰回收站了。但是我可以在视图上创建一个onClick方法,以便在触摸到晶圆厂时使其崩溃并使视图消失吗?即使现在是android:clickable=“true”?当然,仍然可以添加
onClickListener
----
----
<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>
---
---
----
----
<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" />
---
---