浮动操作按钮也与recyclerview一起滚动

时间:2018-04-24 09:29:51

标签: android android-layout

我添加了一个带recyclerview的浮动操作按钮,该按钮也与recyclerview一起滚动我的问题是我在主要活动中有一个底部导航,所以我试图把我的底部导航上方的浮动操作按钮,当我的片段被调用时位于主布局中,而我的工厂显示在recyclerview的末尾,并且它还与recyclerview一起滚动我如何才能制作它在MainActivity中调用片段时不滚动。

请提供任何帮助

我的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>

2 个答案:

答案 0 :(得分:2)

使用 RelativeLayout 作为根目录布局

并使用android:layout_alignParentBottom="true"和             android:layout_alignParentRight="true" FloatingActionButton 附加在屏幕底部

示例代码

<?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>

答案 1 :(得分:1)

您应该将浮动操作按钮放在嵌套滚动视图之外..

相关问题