android - 新的 android 支持设计库,屏幕外滚动 tablayout 不工作

标签 android material-design android-design-library android-support-design

尝试使用新的支撑设计库。在我的布局中,我希望 ToolBar 保留在屏幕顶部,但让 TabLayout 在用户向下滚动时离开屏幕。但看起来 ViewPager 位于 AppBarLayout 下方。我使用这篇博文作为引用 https://medium.com/ribot-labs/exploring-the-new-android-design-support-library-b7cda56d2c32

这是布局,在 ViewPager 中包含由回收器 View 组成的 Fragments

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="match_parent"
android:background="@color/material_grey50"
android:clickable="true">

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tabLayout" />


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


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar_list"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/toolbar_list"
        android:background="?attr/colorPrimary"
        android:scrollbars="horizontal"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|enterAlways"
        app:tabGravity="center" />


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


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab_post"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="16dp"
    android:layout_marginRight="16dp"
    android:elevation="3dp"
    android:src="@drawable/ic_videocam_white_36dp"
    app:backgroundTint="@color/accent"
    app:fabSize="normal" />

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

最佳答案

不要忘记在 viewpager 中设置:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

关于android - 新的 android 支持设计库,屏幕外滚动 tablayout 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30929794/

相关文章:

java - Android - 避免在 onResume 与 onActivityResult 中设置文本字段值的冲突

html - 对齐网格中的组件 : MDL

android - 在 Android 4.4 或更低版本上将 FAB 置于前台

Android:如何使用支持 25.0.0 的 Espresso 2.2.2?

Android Material 设计 - Material Motion

android - 无法在 Firebase 上上传混淆映射文件

android - 将相册添加到 Android 照片库(在代码中)

java - 如何将一个包引用为另一个包中的 jar?

适用于 Pre-Lollipop 设备的具有弯曲背景的 Android Ripple 按钮

android - 如何禁用底部导航 View 的菜单项?