在Android中单击FloatingActionButton时单击RecyclerView项

在Android中单击FloatingActionButton时单击RecyclerView项,android,android-recyclerview,onclicklistener,floating-action-button,Android,Android Recyclerview,Onclicklistener,Floating Action Button,我的应用程序中有一个FloatingActionButton在RecyclerView上。按钮显示ok,但当我单击它时,它下面的RecyclerView项将获得click事件,而不是按钮。如果我将回收视图设置为显示在浮动操作按钮上,按钮按预期工作 如何解决此问题,并使用按钮获取单击事件 谢谢。在屏幕上使用框架布局。您可以获取所有单击事件、项目或浮动按钮 <FrameLayout android:layout_width="match_parent" andr

我的应用程序中有一个
FloatingActionButton
RecyclerView
上。
按钮显示ok,但当我单击它时,它下面的
RecyclerView
项将获得click事件,而不是按钮。如果我将
回收视图
设置为显示在
浮动操作按钮
上,
按钮
按预期工作

如何解决此问题,并使用
按钮
获取单击事件


谢谢。

在屏幕上使用框架布局。您可以获取所有单击事件、项目或浮动按钮

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">
 <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />
</FrameLayout>

对屏幕使用框架布局。您可以获取所有单击事件、项目或浮动按钮

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white">
 <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />
</FrameLayout>

只有在未将onClick Listener设置为启用
FloatingActionButton
时,才会发生这种情况。所以只要将onClick Listener设置为
FloatingActionButton
您的问题就会得到解决

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Your code to do something if you have
        }
});

如果要执行某个操作,只需实现一个如上所述的空侦听器。

只有在未将onClick listener设置为on
FloatingActionButton
的情况下,才会发生这种情况。所以只要将onClick Listener设置为
FloatingActionButton
您的问题就会得到解决

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Your code to do something if you have
        }
});

如果要执行操作,只需像上面那样实现一个空侦听器。

将FAB放入相对布局或线性布局中,并将布局属性设置为android:clickable=“true”android:focusableInTouchMode=“true”及其done.FAB.bringToFront()并在xml中添加clickable:true如果使用android:clickable=“false”android:enabled=“false”android:focusableInTouchMode=“false”对于按钮,如果在按钮上设置OnClick Listener,则需要单击。将晶圆厂放在相对布局或线性布局中,并将该布局属性设置为android:clickable=“true”android:focusableInTouchMode=“true”及其done.FAB.bringToFront()如果您使用android:clickable=“false”android:enabled=“false”android:focusableInTouchMode=“false”为按钮添加clickable:true,则无论您在按钮上设置OnClick Listener是否需要单击,这都应该是可接受的答案。这是正确的。这应该是公认的答案。这是正确的。