首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >滚动ToolBar Android

滚动ToolBar Android
EN

Stack Overflow用户
提问于 2016-04-08 10:41:40
回答 1查看 633关注 0票数 1

在TabLayout中,我有两个选项卡,其中在第一个选项卡中将FrameLayout与recyclerView放在一起,在第二个选项卡中放置带有LinerLayout的ScrollView。在任何选项卡中滚动时,我都需要隐藏ToolBar。当我在第一个选项卡工具栏中滚动RecyclerView时,当我在第二个选项卡中滚动时,它不是。不能忍受为什么。

我有这个main_acrivity.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<FrameLayout 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/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinator"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            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.TabLayout
                android:id="@+id/tab_layout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:tabIndicatorColor="@android:color/background_light"
                app:tabSelectedTextColor="@android:color/background_light"
                app:tabTextColor="@android:color/background_light"/>

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



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

</FrameLayout>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-08 11:37:38

新的滚动行为将不适用于常规的android.widget.ScrollView,因为它不支持嵌套滚动。

滚动行为依赖于支持嵌套滚动的视图,在视图树上传播滚动事件,以便工具栏知道何时滑动和隐藏。

它与RecyclerView一起工作的原因是它默认支持嵌套滚动。

你需要的是一个NestedScrollView

NestedScrollView就像ScrollView一样,但它支持在新版本和旧版本的Android上同时充当嵌套滚动父级和子级。默认情况下,启用嵌套滚动。

因此,在具有ScrollView的布局中,将其替换为android.support.v4.widget.NestedScrollView,滚动视图行为将如预期的那样工作:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- your content here...... -->

</android.support.v4.widget.NestedScrollView>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36506969

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文