Clicking the ActionButton floating button on the right corner allows you to click the RecyclerView element.

I want to add a Floating Action Button to recyclerview, but the problem is when I click the Floating Action button. The Recyclerview element gets a click on how to remove this problem.

see below code

<RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".screens.ShowSubjectsFrag" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <android.support.v7.widget.RecyclerView android:id="@+id/MainList" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> </android.support.v7.widget.RecyclerView> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/ic_input_add" app:layout_anchor="@id/MainList" android:layout_margin="@dimen/fab_margin" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> 
+6
source share
3 answers

Write View#onClickListener for the FloatingActionButton in the Activity/Fragment , because currently your FloatingActionButton not registered for any event . Had the same Greetings problem

+7
source

Try using the code below in xml:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/MainList" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center"> </android.support.v7.widget.RecyclerView> </RelativeLayout> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/ic_input_add" app:layout_anchor="@id/MainList" android:layout_margin="@dimen/fab_margin" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> 

Place both views in different layouts so that they can belong to different levels.

For more information check design methods here .

Thanks..!!

-1
source

You use a RecyclerView inside a RelativeLayout , and you set its width and height to match_parent ! Basically your RecyclerView hides your FloatingActionButton .

If I were you, I would do the following:

 <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".screens.ShowSubjectsFrag" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"> <android.support.v7.widget.RecyclerView android:id="@+id/MainList" android:layout_width="match_parent" android:layout_height="300dp" <!-- Use a fixed height over here --> android:layout_alignParentTop="true"> </android.support.v7.widget.RecyclerView> <android.support.design.widget.FloatingActionButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@android:drawable/ic_input_add" app:layout_anchor="@id/MainList" android:layout_margin="@dimen/fab_margin" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" /> </RelativeLayout> 

I also suspect layout_anchor not required. Try also to remove it. Regardless, the main problem seems to be that your RecyclerView hiding your FloatingActionButton . You can check this in the field of design (if you are using Android Studio).

Let me know if this helps, otherwise I will dive deep further!

-1
source

All Articles