Android滚动工具栏以及其他组合视图

时间:2018-12-22 08:32:17

标签: android android-layout

在我的Android应用程序中,我有ToolbarSlidingLayer,这是一个简单的库,它从FrameLayout扩展到可以在应用程序上滑动。现在,当我尝试在该视图中使用工具栏时,必须将其设置为FrameLayout,通过此操作滚动工具栏无法正常工作。

我将app:layout_scrollFlags="scroll|enterAlways"<android.support.v7.widget.Toolbar移到了FrameLayout,但是再次滚动则不起作用。例如,我使用工具栏的视图是:

enter image description here

现在如何在此视图中使用app:layout_scrollFlags="scroll|enterAlways"和滚动工具栏?

我的xml布局是:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:slidingLayer="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_scrollFlags="scroll|enterAlways">

    <com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer
        android:id="@+id/sliderTabPages"
        android:layout_width="match_parent"
        android:layout_height="130dp"
        android:layout_marginLeft="8dp"
        android:layout_marginTop="56dp"
        android:layout_marginRight="8dp"
        android:elevation="5dp"
        app:offsetDistance="30dp"
        app:slidingEnabled="true"
        app:stickTo="top"
        slidingLayer:changeStateOnTap="true">

    </com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer>

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            app:contentInsetStartWithNavigation="0dp"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/Toolbar.Light">

            <android.support.constraint.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            />

            </android.support.constraint.ConstraintLayout>
        </android.support.v7.widget.Toolbar>

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

</FrameLayout>

1 个答案:

答案 0 :(得分:0)

尝试一下:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:slidingLayer="http://schemas.android.com/apk/res-auto">

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

        <!--Can use any layout for your content important thing is app:layout_behavior="@string/appbar_scrolling_view_behavior"-->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <com.test.sample.Core.Libraries.SlidingLayer.SlidingLayer
                android:id="@+id/sliderTabPages"
                android:layout_width="match_parent"
                android:layout_height="130dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="56dp"
                android:layout_marginRight="8dp"
                android:elevation="5dp"
                app:offsetDistance="30dp"
                app:slidingEnabled="true"
                app:stickTo="top"
                slidingLayer:changeStateOnTap="true" />

            <!--Other content-->
            <!--Note that this content has to have scrollable view like RecyclerView-->
            <!--Example-->
            <RecyclerView
                android:id="@+id/yoursScrollableView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </FrameLayout>

        <com.google.android.material.appbar.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <!--Collapsing toolbar-->
            <!--You can put any kind of view for scrolling important thing is app:layout_scrollFlags="scroll|enterAlways"-->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarThatGoingToScroll"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/white"
                app:contentInsetStartWithNavigation="0dp"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/Toolbar.Light" />

        </com.google.android.material.appbar.AppBarLayout>
    </android.support.design.widget.CoordinatorLayout>
</layout>