繁体   English   中英

在其 ViewPager 中使用带有 ScrollView 的片段隐藏选项卡式活动中的工具栏

[英]Hiding Toolbar in tabbed activity with fragment with ScrollView in its ViewPager

我想在滚动 ViewPager 片段中的滚动视图时隐藏工具栏,但是当我滚动时,只有滚动视图的部分正在滚动(工具栏在其位置)。

考虑一下,当我在 tablayout(标题部分,id-tabs)上滚动时,它会隐藏工具栏

<androidx.coordinatorlayout.widget.CoordinatorLayout 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"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">


        <Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="5dp"
            app:layout_scrollFlags="scroll|enterAlways|snap" />


        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            app:tabIndicatorColor="@android:color/white" />
    </com.google.android.material.appbar.AppBarLayout>

   <androidx.viewpager.widget.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

在我的 java 文件中是

    Toolbar toolbar = findViewById(R.id.toolbar);      

    toolbar.setTitle("304 Pramukh");

我的片段 Xml 文件是

<FrameLayout 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"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".Fragments.CommunityFragment">

    <!-- TODO: Update blank fragment layout -->
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

             <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/rv_family"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
       </LinearLayout>
    </ScrollView>
</FrameLayout>```

这只需要一个小改动,只需将滚动视图替换为嵌套滚动视图......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM