如何在坐标布局上隐藏图像视图(如fab隐藏在滚动上)?

时间:2016-10-26 10:40:27

标签: android android-layout layout behavior android-coordinatorlayout

我希望隐藏/消失图像视图(如fab),当它的滚动作为其坐标布局行为时,其行为首先表现为intaally

滚动时

scolling

scrolling

这是我的布局xml

<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:id="@+id/lyoutFeedLoadMore"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:layout_alignParentBottom="true"
    android:background="#FAFAFA"
    android:gravity="center"
    android:visibility="gone">

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

<View
    android:id="@+id/bottomView"
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:layout_alignParentBottom="true"
    android:background="@color/white" />

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.photex.urdu.textonphotos.activities.ScrollingActivity"
    android:layout_above="@+id/bottomView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/main.appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true"
        android:orientation="vertical"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main.collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/white">

                <FrameLayout
                    android:id="@+id/main.framelayout.title"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/main.backCover"
                    android:layout_gravity="bottom"
                    android:layout_marginLeft="120dp"
                    android:layout_marginStart="120dp"
                    android:background="@color/white"
                    android:orientation="vertical"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.3">

                    <LinearLayout
                        android:id="@+id/pfInfo"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"

                        android:baselineAligned="false"
                        android:orientation="horizontal"
                        android:weightSum="3">

                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="12dp"
                            android:layout_marginStart="12dp"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/txtCountPost"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="12dp"
                                android:text="-"
                                android:textColor="@android:color/black"
                                android:textSize="18sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/txtPost"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                android:text="post"
                                android:textColor="@android:color/black" />
                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/layout_followers"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/txtCountFollowers"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="12dp"
                                android:text="-"
                                android:textColor="@android:color/black"
                                android:textSize="18sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/txtFollowers"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                android:text="followers"
                                android:textColor="@android:color/black" />
                        </LinearLayout>

                        <LinearLayout
                            android:id="@+id/layout_following"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:orientation="vertical">

                            <TextView
                                android:id="@+id/txtCountFollowing"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="12dp"
                                android:text="-"
                                android:textColor="@android:color/black"
                                android:textSize="18sp"
                                android:textStyle="bold" />

                            <TextView
                                android:id="@+id/txtFollowing"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="8dp"
                                android:text="following"

                                android:textColor="@android:color/black" />
                        </LinearLayout>
                    </LinearLayout>

                </FrameLayout>

                <LinearLayout
                    android:id="@+id/main.section"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/main.framelayout.title"
                    android:layout_margin="16dp"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/txtName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:ellipsize="end"
                        android:maxLines="1"
                        android:text="nasdnfasdnfasdhfjasdhfahsdfahsdasdfa"
                        android:textColor="@android:color/black"
                        android:textSize="16sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/txtBio"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:ellipsize="end"
                        android:maxLines="5"
                        android:text="fgsfgdfgsdfgdfg"
                        android:textColor="@android:color/black"
                        android:textSize="16sp"
                        android:visibility="visible" />

                    <TextView
                        android:id="@+id/txtFallowedBy"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="8dp"
                        android:ellipsize="end"
                        android:maxLines="2"
                        android:text="Success Diaries"
                        android:textColor="@android:color/black"
                        android:textSize="16sp"
                        android:visibility="gone" />

                </LinearLayout>

                <Button
                    android:id="@+id/btnFollowEdit"
                    android:layout_width="wrap_content"
                    android:layout_height="35dp"
                    android:layout_below="@+id/main.section"
                    android:layout_centerInParent="true"
                    android:background="@drawable/bg_rectangle_white"
                    android:minWidth="150dp"
                    android:onClick="onClick"
                    android:text="Follow"
                    android:textColor="@android:color/black"
                    android:visibility="visible" />

                <View
                    android:id="@+id/view"
                    android:layout_width="match_parent"
                    android:layout_height="32dp"
                    android:layout_below="@+id/btnFollowEdit"
                    android:layout_marginBottom="12dp"
                    android:visibility="invisible" />

                <ImageView
                    android:id="@+id/main.backCover"
                    android:layout_width="match_parent"
                    android:layout_height="150dp"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    android:layout_alignParentTop="true"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/sea"
                    app:layout_collapseMode="parallax" />
            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarUser"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"

                app:popupTheme="@style/AppTheme.PopupOverlay">

                <TextView

                    android:id="@+id/txtNameToolbar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@android:color/white"
                    android:textSize="18sp" />
            </android.support.v7.widget.Toolbar>

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

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





    <ProgressBar
        android:id="@+id/progressBarMain"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="300dp" />
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvFeeds"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srlContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

    </android.support.v4.widget.SwipeRefreshLayout>

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/ivUserProfilePhoto"
        android:layout_width="92dp"
        android:layout_height="92dp"
        android:layout_margin="@dimen/fab_margin"
        android:src="@mipmap/ic_launcher"
        app:civ_border_width="2dp"
        app:layout_anchor="@id/main.backCover"
        app:layout_anchorGravity="bottom|left|end" />
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

我想要的行为如facebook滚动

首先in normal

滚动on scroll[![][5]] 6

1 个答案:

答案 0 :(得分:0)

尝试将您的父布局设为android.support.design.widget.CoordinatorLayout,然后在该布局中设置所有内容,然后选中this

 <android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true">
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginBottom="32dp"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">
                <ImageView
                    android:id="@+id/header"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/header"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax" />
                <android.support.v7.widget.Toolbar
                    android:id="@+id/anim_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
        <android.support.v7.widget.RecyclerView
            android:id="@+id/scrollableview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
        <android.support.design.widget.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/fab_margin"
            android:clickable="true"
            android:src="@drawable/ic_action_add"
            app:layout_anchor="@+id/appbar"
            app:layout_anchorGravity="bottom|right|end" />

    </android.support.design.widget.CoordinatorLayout>