折叠线性布局

问题描述 投票:0回答:2

我正在研究Android应用程序只是为了学习目的在应用程序中我有一个相对布局,其中有另一个线性布局和RecyclerView。 RecyclerView用于显示特定用户的朋友列表,线性布局是为用户提供一个选项,可以点击它并重定向到另一个可以添加新朋友的活动。这是.xml文件。

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

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/add_new_friend"
            android:gravity="center"
            android:textSize="24sp"
            android:textStyle="bold"
            android:layout_margin="16dp"
            android:textColor="@color/addNewFriendTextColor"/>

    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/friendsRecyclerView"
        android:layout_below="@+id/addFriendLayout"/>

</RelativeLayout> 

我想做的事?

- 当用户向上滚动时,我希望线性布局隐藏在工具栏后面,然后当用户向下滚动以折叠并变得可见时。

这是一个类似我的情况,但我不明白该怎么做。 Stack Overflow link

android android-linearlayout android-collapsingtoolbarlayout
2个回答
1
投票

看看这个page,它似乎描述了你想要实现的行为。


1
投票

检查此代码..我希望这可能对您有所帮助

<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/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="44dp"
            app:expandedTitleMarginStart="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorAccent"
                android:orientation="vertical"
                android:padding="20dp">

                 <!--your design here-->

              </LinearLayout>
             <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin" />
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
© www.soinside.com 2019 - 2024. All rights reserved.