带有其他组合 View 的 Android 滚动工具栏

标签 android android-layout

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

我搬家了app:layout_scrollFlags="scroll|enterAlways"来自 <android.support.v7.widget.ToolbarFrameLayout但滚动它不再起作用。例如我的工具栏 View 是:

enter image description here

现在我该如何使用 app:layout_scrollFlags="scroll|enterAlways"和带有此 View 的滚动工具栏?

我的 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>

最佳答案

试试这个:

<?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>

关于带有其他组合 View 的 Android 滚动工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53894167/

相关文章:

android - 使用自定义属性设置View子类的自定义属性?

android - 键盘重叠自定义编辑文本

java - 内存不足错误 - 可能是由于内存泄漏?

javascript - Phonegap 应用程序中的谷歌地图 V3 使用限制

android - 在不访问 Activity 的情况下在 Android 的主线程上执行代码?

android - 处理 AsyncTask 的屏幕方向

android - 无法使用 Picasso 从 URL 设置 LinearLayout BackgroundResource

android - 如何以编程方式为 LinearLayout 指定 layout_below?

android - gridlayout 的子级可见性消失了

Android NDK - 尝试用 NoMemoryError 捕获