【问题标题】:hide toolbar and keep tapLaout when scroll in using viewPager [duplicate]使用viewPager滚动时隐藏工具栏并保持tapLaout [重复]
【发布时间】:2020-02-25 15:35:31
【问题描述】:

滚动viewPager时我需要隐藏toolBar(Header)并保持tapLayout在顶部

viewPager 将包含包含 RecyclerView 的片段

告诉我是否有其他编码方式

如果有办法修复此代码,这对我来说是最好的

My layout design

这是我的 XML 代码

<?xml version="1.0" encoding="utf-8"?>
<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"
    android:fitsSystemWindows="true">


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

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="@color/white"
            app:layout_collapseMode="parallax"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                android:id="@+id/homeHeader"
                layout="@layout/user_profile_header" />


        </com.google.android.material.appbar.CollapsingToolbarLayout>


    </com.google.android.material.appbar.AppBarLayout>


    <LinearLayout
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <!--Tab-->
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed" />


        <!--ViewPager-->
        <androidx.viewpager.widget.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


</androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

  • 你想完全隐藏工具栏(可能存在于你的标题内)或标题布局。???
  • 当我在 viewPager 的片段中滚动 RecyclerView 时,我需要隐藏工具栏——就像 instagram 个人资料页面一样(我需要将标签保留在活动的顶部)

标签: android


【解决方案1】:

getSupportActionBar().hide();

将这部分代码放在你的 oncreate 中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多