工具栏不会滚动型崩溃的CoordinatorLayout儿童 [英] Toolbar will not collapse with Scrollview as child of CoordinatorLayout

查看:332
本文介绍了工具栏不会滚动型崩溃的CoordinatorLayout儿童的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想跟随谷歌文档的使用CoordinatorLayout,但我有一个问题,CoordinatorLayout内的滚动型。基本上,工具栏通常会用RecyclerView或列表视图滚动时向下塌陷。现在,随着滚动型也不会崩溃。

 < android.support.design.widget.CoordinatorLayout
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>

    <滚动型
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        应用程序:layout_behavior =@字符串/ appbar_scrolling_view_behavior
        >

        <的TextView
            机器人:ID =@ + ID / tv_View
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:layout_gravity =中心
            机器人:重力=中心
            机器人:文本=@字符串/填料
            风格=@风格/ TextAppearance.AppCompat.Large
            />

    < /滚动型>

    < android.support.design.widget.AppBarLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        >
        < android.support.v7.widget.Toolbar
            机器人:ID =@ + ID /工具栏
            机器人:layout_width =match_parent
            机器人:layout_height =?ATTR / actionBarSize
            应用程序:layout_scrollFlags =滚动| enterAlways
            />

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

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

解决方案

滚动型不与 CoordinatorLayout 。你必须使用 NestedScrollView ,而不是滚动型

I am trying to follow the Google Docs on using the CoordinatorLayout but i am having an issue with the ScrollView inside the CoordinatorLayout. Basically, the Toolbar normally would collapse with a RecyclerView or a Listview when scrolling down. Now with a ScrollView it will not collapse.

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <TextView
            android:id="@+id/tv_View"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/filler"
            style="@style/TextAppearance.AppCompat.Large"
            />

    </ScrollView>

    <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"
            app:layout_scrollFlags="scroll|enterAlways"
            />

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

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

解决方案

The ScrollView does not cooperate with the CoordinatorLayout. You have to use NestedScrollView instead of ScrollView

这篇关于工具栏不会滚动型崩溃的CoordinatorLayout儿童的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆