首页 > 解决方案 > 在Android中向下滚动ListView时如何隐藏工具栏?(Xamarin)

问题描述

我在屏幕顶部有一个工具栏和一个 TabLayout,下面有一个 ViewPager。ViewPager 为每个选项卡显示不同的片段,但这些片段中的每一个本质上只是一个带有 ListView 的 RelativeLayout。我想让它在 ListView 向下滚动时,工具栏将隐藏自己(移到屏幕顶部看不见),当它向上滚动时,工具栏将再次出现。

我尝试遵循一些指南,但它似乎不起作用。更不用说我能找到的所有内容要么已经过时,要么使用了 AppBarLayout 下方的 RecyclerView。我需要一个 ViewPager 的选项卡,所以我不能有 RecylerView 那里。

我正在使用 API 级别 30,并且正在模拟的 Pixel 2 上进行测试。

这就是我的 XML 的样子:

<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.support.design.widget.AppBarLayout android:id="@+id/appbar"
                                                android:layout_width="match_parent"
                                                android:layout_height="wrap_content"
                                                app:layout_scrollFlags="enterAlways">
        <android.support.v7.widget.Toolbar android:layout_width="match_parent"
                                           android:layout_height="?attr/actionBarSize">
            <TextView android:id="@+id/title"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:gravity="center_vertical"/>
        </android.support.v7.widget.Toolbar>
        <android.support.design.widget.TabLayout android:id="@+id/tabs"
                                                 android:layout_width="match_parent"
                                                 android:layout_height="32dp"
                                                 android:layout_below="@id/title"
                                                 android:layout_marginBottom="4dp"
                                                 app:tabMinWidth="96dp"
                                                 app:tabIndicatorHeight="4dp"
                                                 app:tabIndicatorFullWidth="false"
                                                 app:tabMode="scrollable">
            <android.support.design.widget.TabItem android:text="@string/tab_1"/>
            <android.support.design.widget.TabItem android:text="@string/tab_2"/>
            <android.support.design.widget.TabItem android:text="@string/tab_3"/>
        </android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager android:id="@+id/content"
                                       android:layout_width="match_parent"
                                       android:layout_height="match_parent"
                                       android:layout_below="@id/appbar"
                                       app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

任何帮助将不胜感激,谢谢。

标签: androidandroid-layoutxamarinxamarin.android

解决方案


推荐阅读