浮动操作按钮不会隐藏在视差效果中

时间:2016-07-21 08:42:04

标签: android android-coordinatorlayout floating-action-button

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:id="@+id/root_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.groomefy.consumer.Trending.DetailedActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="320dp"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp"
            app:layout_collapseMode="parallax"
            app:layout_collapseParallaxMultiplier="0.9">

            <ImageView
                android:id="@+id/main_image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/placeholder"
                app:layout_collapseMode="parallax" />

            <ImageView
                android:id="@+id/curve_image"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:paddingTop="10dp"
                android:src="@drawable/postdetail_curve"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.3" />
        </RelativeLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/white"
            app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay">

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="10dp">

                    <ImageButton
                        android:id="@+id/btn_cancel"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:background="@android:color/transparent"
                        android:padding="10dp"
                        android:src="@drawable/backicon" />

                    <com.groomefy.consumer.fontutils.OpenSansBold
                        android:id="@+id/title_text_view"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="@string/fragment_blogs"
                        android:textColor="@color/title_text_color"
                        android:textSize="@dimen/title_text_size"
                        android:textStyle="bold" />

                    <ImageView
                        android:id="@+id/iv_more"
                        android:layout_width="@dimen/more_btn_height"
                        android:layout_height="@dimen/more_btn_height"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:scaleType="center"
                        android:src="@drawable/more" />

                </RelativeLayout>

                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#a6a6a6" />

            </LinearLayout>
        </android.support.v7.widget.Toolbar>

    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/like_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:layout_marginLeft="55dp"
    android:src="@drawable/like"
    app:layout_anchor="@id/curve_image"
    app:layout_anchorGravity="center_vertical" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fav_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/add_to_stylebook"
    app:layout_anchor="@id/curve_image"
    app:layout_anchorGravity="center" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/share_img"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="50dp"
    android:src="@drawable/share"
    app:layout_anchor="@id/curve_image"
    app:layout_anchorGravity="center_vertical|right"
    app:layout_collapseMode="parallax" />

  

这是我的xml我想在滚动时隐藏浮动动作按钮,但它们只是粘在顶部而不是隐藏   我试图以不同的方式,我也看到this示例

请告诉我我做错了什么

1 个答案:

答案 0 :(得分:1)

您正在使用RecycleView,因此请以FloatingActionButton方式隐藏RecycleView以这种方式滚动。

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener(){
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy){
            if (dy > 0)
                fabAddNew.hide();
            else if (dy < 0)
                fabAddNew.show();
        }
    });

dyparallel