【问题标题】:Toolbar is not hiding when i scroll content layout当我滚动内容布局时工具栏没有隐藏
【发布时间】:2017-05-19 05:39:33
【问题描述】:
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"/>

    </android.support.design.widget.AppBarLayout>


    <android.support.v4.view.ViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/tab_bar" />

    <com.whl.handytabbar.HandyTabBar
        android:id="@+id/tab_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:layout_alignParentBottom="true"
        android:layout_gravity="bottom"
        android:background="@drawable/custom_shadow" />

</android.support.design.widget.CoordinatorLayout>

【问题讨论】:

    标签: android android-layout android-studio android-fragments


    【解决方案1】:

    工具栏在一个 AppBarLayout 里面,它可能在你的 CoordinatorLayout 里面,那么这样的东西应该可以工作。

    AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
            appBarLayout.setExpanded(true, true);
    

    或者折叠工具栏然后这样的东西应该可以工作

    AppBarLayout appBarLayout = (AppBarLayout)findViewById(R.id.appBar);
            appBarLayout.setExpanded(false, true);
    

    【讨论】:

    【解决方案2】:

    点击此链接,您将在这里得到答案:

    How to hide ToolBar when i scrolling content up in android

    【讨论】:

      【解决方案3】:

      您在滚动视图中需要此app:layout_behavior="@string/appbar_scrolling_view_behavior",如下所示:

       <android.support.v7.widget.RecyclerView
          android:id="@+id/rvToDoList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior">
      

      我们需要定义 AppBarLayout 和 View 之间的关联 那将被滚动。将 app:layout_behavior 添加到 RecyclerView 或 任何其他能够嵌套滚动的视图,例如 NestedScrollView。 支持库包含一个特殊的字符串资源 @string/appbar_scrolling_view_behavior 映射到 AppBarLayout.ScrollingViewBehavior,用于通知 在此特定视图上发生滚动事件时的 AppBarLayout。这 必须在触发事件的视图上建立行为。

      你应该看看This Guide

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-05-30
        • 1970-01-01
        • 2018-09-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多