简体   繁体   English

工具栏不会在CoordinatorLayout中滚动时隐藏/显示

[英]Toolbar does not Hide/Shown on Scrolling in CoordinatorLayout

I'm trying to auto hide and show depends on scrolling of TextView implemented in ViewPager. 我试图自动隐藏和显示取决于在ViewPager中实现的TextView滚动。 But, Toolbar never hides on scrolling. 但是,工具栏永远不会在滚动时隐藏。 Main XML activity_data_display.xml 主要XML activity_data_display.xml

<android.support.v4.widget.DrawerLayout 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:id="@+id/activity_drawer"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.regio.developers.upasana.DataDisplayActivity">

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/activity_data_display"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/data_viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

</android.support.v4.widget.DrawerLayout>

Here's the layout that is inflated in ViewPager data_swipe_layout.xml 这是ViewPager中膨胀的布局data_swipe_layout.xml

<android.support.v4.widget.NestedScrollView
 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="wrap_content"
 app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/dataviewpager_textview"
        android:textColor="#FFF"
        android:paddingTop="20dp"
        android:paddingBottom="20dp"
        android:paddingRight="35dp"
        android:paddingLeft="35dp"
        android:textSize="20sp"
        android:gravity="center"/>

</android.support.v4.widget.NestedScrollView>

added Toolbar Layout file toolbar_layout.xml 添加了工具栏布局文件toolbar_layout.xml

<?xml version="1.0" encoding="utf-8"?>
 <android.support.v7.widget.Toolbar
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:id="@+id/toolbar"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:background="?attr/colorPrimary"
 android:fitsSystemWindows="true"
 android:minHeight="?attr/actionBarSize"
 app:theme="@style/ToolBarStyle"
 app:layout_scrollFlags="scroll|enterAlways"
>

</android.support.v7.widget.Toolbar>

Please solve my problem? 请解决我的问题?

I've tried different ways to make it work like using NestedScrollView in Main XML file. 我尝试了多种方法使其工作,例如在Main XML文件中使用NestedScrollView。 But, it just does not help. 但是,这无济于事。

Please try implementing yourself then give me solution for this. 请尝试实现自己,然后为我提供解决方案。

Remember I've used TextView which contains hundreds of of line of text. 记住,我使用了包含数百行文本的TextView。

Also, how to implement ScrollBar which can be drag-able manually for the TextView in ViewPager? 另外,如何实现可在ViewPager中为TextView手动拖动的ScrollBar?

You are using the included layout of toolbar you should make this property app:layout_scrollFlags="scroll|enterAlways" 您正在使用工具栏的随附布局,应将此属性设为app:layout_scrollFlags =“ scroll | enterAlways”

for the AppBarLayout or write that code of toolbar in AppBarLayout. 用于AppBarLayout或在AppBarLayout中编写工具栏的代码。

Hope this helps. 希望这可以帮助。

Check this.
 it is working
<android.support.v4.widget.DrawerLayout 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:id="@+id/activity_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinatorLayout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbarsdfs"
            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.widget.NestedScrollView
        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="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/dataviewpager_textview"
            android:textColor="#FFF"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"
            android:paddingRight="35dp"
            android:paddingLeft="35dp"
            android:textSize="20sp"
            android:text=""
            android:gravity="center"/>

    </android.support.v4.widget.NestedScrollView>

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

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

相关问题 仅在特定片段中滚动时,CoordinatorLayout 隐藏工具栏 - CoordinatorLayout hide toolbar when scrolling only in specific fragment 使用CoordinatorLayout滚动隐藏工具栏 - Hide Toolbar on scroll with CoordinatorLayout 通过添加工具栏时,CoordinatorLayout滚动无法正常工作<include layout =“ ” /> - CoordinatorLayout scrolling does not work while Toolbar is added via <include layout =“ ” /> 如何在CoordinatorLayout中停止滚动工具栏 - How to stop scrolling toolbar in coordinatorlayout 我无法在CoordinatorLayout中隐藏工具栏 - I can not hide Toolbar in CoordinatorLayout 在CoordinatorLayout上以编程方式隐藏/显示工具栏 - Hide/Show Toolbar programmatically on CoordinatorLayout 使用CoordinatorLayout隐藏工具栏,但在片段上使用RecyclerView - Hide Toolbar with CoordinatorLayout, but RecyclerView on a fragment 滚动时在CoordinatorLayout中隐藏工具栏和BottomBar-在透明状态栏下可见 - Hide Toolbar and BottomBar in CoordinatorLayout when scrolling - visible under transparent status bar CoordinatorLayout内的Viewpager不滚动“折叠”工具栏 - Viewpager inside CoordinatorLayout not scrolling the Collapsing toolbar 向下滚动后隐藏CoordinatorLayout中的工具栏 - Hiding toolbar in CoordinatorLayout after scrolling down
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM