簡體   English   中英

工具欄不會在CoordinatorLayout中滾動時隱藏/顯示

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

我試圖自動隱藏和顯示取決於在ViewPager中實現的TextView滾動。 但是,工具欄永遠不會在滾動時隱藏。 主要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>

這是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>

添加了工具欄布局文件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>

請解決我的問題?

我嘗試了多種方法使其工作,例如在Main XML文件中使用NestedScrollView。 但是,這無濟於事。

請嘗試實現自己,然后為我提供解決方案。

記住,我使用了包含數百行文本的TextView。

另外,如何實現可在ViewPager中為TextView手動拖動的ScrollBar?

您正在使用工具欄的隨附布局,應將此屬性設為app:layout_scrollFlags =“ scroll | enterAlways”

用於AppBarLayout或在AppBarLayout中編寫工具欄的代碼。

希望這可以幫助。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM