簡體   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