如何在折叠工具栏布局中放置工具栏下方的布局?

7 android android-layout android-collapsingtoolbarlayout

我想在我的应用程序中折叠工具栏布局.为此,我在应用栏中添加了折叠工具栏.我在布局下添加了一些文本视图的相对布局.这个相对布局我想显示在工具栏下面,它应该折叠到工具栏.

就像我已经添加了这个,它与工具栏合并.如下所示:

在此输入图像描述

编辑:使用嵌套滚动视图编辑.滚动到状态栏,应滚动到工具栏.

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="140dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:fitsSystemWindows="true">

    <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:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:titleEnabled="false">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/toolbar"
                android:fitsSystemWindows="true"
                android:gravity="bottom"
                android:paddingLeft="30dp"
                android:scaleType="centerCrop">


                <TextView
                    android:id="@+id/eventName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:text="Event Name"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/date"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/eventName"
                    android:layout_marginTop="10dp"
                    android:text="Date"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

                <TextView
                    android:id="@+id/time"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/date"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="10dp"
                    android:text="Time"
                    android:textColor="#ffffff"
                    android:textSize="14sp"/>

            </RelativeLayout>

        </LinearLayout>

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

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

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <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"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.example.siddhi.meavita.Activities.PlanDetailsActivity"
        tools:showIn="@layout/activity_plan_details">


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="PLAN"
            android:layout_centerHorizontal="true"
            android:textAppearance="@android:style/TextAppearance.Large"
            android:id="@+id/textView6"
            android:layout_marginTop="10dp" />

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="false"
            android:layout_alignParentStart="false"
            android:layout_below="@+id/textView6"
            android:layout_marginTop="40dp">

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                style="?android:attr/borderlessButtonStyle"
                android:text="Schedule"
                android:id="@+id/schedule"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/list_background" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                style="?android:attr/borderlessButtonStyle"
                android:text="Check List"
                android:id="@+id/button4"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:text="Vendors"
                style="?android:attr/borderlessButtonStyle"
                android:id="@+id/button5"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />

            <Button
                android:layout_width="150dp"
                android:layout_height="40dp"
                android:text="Invitee"
                style="?android:attr/borderlessButtonStyle"
                android:id="@+id/button6"
                android:layout_gravity="center_horizontal"
                android:layout_marginTop="20dp"
                android:background="@drawable/list_background" />
        </LinearLayout>


    </RelativeLayout>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

如何将其放在工具栏下方并向上滚动到工具栏?谢谢..

Cha*_*edi 9

将此行添加到RelativeLayout中.

app:layout_behavior="@string/appbar_scrolling_view_behavior"
Run Code Online (Sandbox Code Playgroud)


Nid*_*ice 5

在RelativeLayout android:layout_marginTop =“?attr / actionBarSize”中添加边距

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/toolbar"
            android:layout_marginTop="?attr/actionBarSize"
            android:fitsSystemWindows="true"
            android:gravity="bottom"
            android:paddingLeft="30dp"
            android:scaleType="centerCrop">
Run Code Online (Sandbox Code Playgroud)


Ale*_*der 1

<?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"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="match_parent"
                                                 android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="140dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:fitsSystemWindows="true">

        <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:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:titleEnabled="false">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

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

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/toolbar"
                    android:fitsSystemWindows="true"
                    android:gravity="bottom"
                    android:paddingLeft="30dp"
                    android:scaleType="centerCrop">


                    <TextView
                        android:id="@+id/eventName"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:text="Event Name"
                        android:textColor="#ffffff"
                        android:textSize="14sp"/>

                    <TextView
                        android:id="@+id/date"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/eventName"
                        android:layout_marginTop="10dp"
                        android:text="Date"
                        android:textColor="#ffffff"
                        android:textSize="14sp"/>

                    <TextView
                        android:id="@+id/time"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/date"
                        android:layout_marginBottom="10dp"
                        android:layout_marginTop="10dp"
                        android:text="Time"
                        android:textColor="#ffffff"
                        android:textSize="14sp"/>

                </RelativeLayout>

            </LinearLayout>

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

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

    <android.support.v4.widget.NestedScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="adlfjsd adsf adsf dsafasd fsda f af dsaf afl djsaflk sjdafl jsalf jsdalf jsdal fjasdl fjalsd jflas jflsa djfdl"
            android:textSize="100sp"/>


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

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)