首页 > 解决方案 > 滚动时如何在工具栏下方固定线性布局

问题描述

我想实现如下所示的图像

图片

我想在工具栏下粘贴一个线性布局,并使其在滚动期间的给定时刻出现

标签: javaandroid

解决方案


检查一下,我已经在代码中为您的项目添加了注释

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

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

                <!-- YOUR ITEMS BETWEEN TABBAR AND APPBAR-->

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

        <LinearLayout
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:descendantFocusability="blocksDescendants"
            android:orientation="vertical">

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

                <!-- YOUR CUSTOM TABBAR-->

                </LinearLayout>

                <android.support.v4.widget.NestedScrollView
                    android:fillViewport="true"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <!-- YOU MAIN CONTENT-->

                </android.support.v4.widget.NestedScrollView>
            </LinearLayout>
        </LinearLayout>
    </android.support.design.widget.CoordinatorLayout>     
</RelativeLayout>

推荐阅读