user9570840
user9570840

Reputation:

floating action button is also scrolling along with recyclerview

I have added a floating action button with recyclerview which is also scrolling along with the recyclerview my problem is that I have a bottom navigation in main activity so I'm trying to put my floating action button above bottom navigation which is in the main layout when my fragment is called but instead my fab is shown at the end of recyclerview and it is also scrolling along with the recyclerview how can I make it not scroll when the fragment is called in MainActivity.

Please any help would be appreciated

My XML

<android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.ct.listrtrial.fragments.FeedFragment">

    <com.ct.listrtrial.Custom.CustomTextViewMedium
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:text="Feed"
        android:paddingTop="10dp"
        android:paddingLeft="15dp"
        android:textSize="35sp"
        android:textColor="@color/White"
        android:layout_weight="1"/>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/feed_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9"

        android:paddingTop="15dp">

    </android.support.v7.widget.RecyclerView>

        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:src="@drawable/ic_search_black_24dp"/>

</LinearLayout>
</android.support.v4.widget.NestedScrollView>

Upvotes: 4

Views: 2235

Answers (2)

Developer Hitesh
Developer Hitesh

Reputation: 124

You Should put floating action button outside of nested scrollview..

Upvotes: 1

AskNilesh
AskNilesh

Reputation: 69689

Use RelativeLayout as Root layout

And Use android:layout_alignParentBottom="true" and android:layout_alignParentRight="true" to attach your FloatingActionButton at bottom of screen

SAMPLE CODE

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            tools:context="com.ct.listrtrial.fragments.FeedFragment">

            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:paddingLeft="15dp"
                android:paddingTop="10dp"
                android:text="Feed"
                android:textColor="@color/White"
                android:textSize="35sp" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/feed_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="9"

                android:paddingTop="15dp">

            </android.support.v7.widget.RecyclerView>


        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:src="@drawable/ic_search_black_24dp" />


</RelativeLayout>

Upvotes: 4

Related Questions