【问题标题】:New android Support Design Library, scroll tablayout offscreen not working新的 android 支持设计库,屏幕外滚动 tablayout 不起作用
【发布时间】:2015-09-04 22:39:17
【问题描述】:

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

这是布局,在 ViewPager 中包含由回收器视图组成的 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>

【问题讨论】:

  • 这里的 layout_behavior 与特定控件一起使用,例如回收器视图或嵌套滚动视图。见demo

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


【解决方案1】:

别忘了在 viewpager 中设置:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

【讨论】:

  • 我也这样做了,但没有任何效果
  • 这可能不是它,但是当 ViewPager 是最后一个孩子而 AppBarLayout 是 CoordinatorLayout 的第一个孩子时,它在我的项目中工作正常。尝试按该顺序重新排序。另外,我看到&lt;/RelativeLayout&gt; 标签添加了您的 sn-p 的底部,所以如果这是之前删除的剩余部分,请尝试删除它。
  • hmm 重新排序也不起作用,您使用的是 design-support 22.2.0 并支持 lib 22.2 吗?如果这个布局在一个片段中会有关系吗?
  • 是的。我什至在片段中使用它。再三考虑,删除不必要的 relativelayout,只在 FAB 上使用 layout_anchor 和 layout_gravity。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-04
  • 1970-01-01
  • 2015-08-24
  • 1970-01-01
  • 2015-10-10
  • 2023-03-04
  • 2015-10-19
相关资源
最近更新 更多