【问题标题】:CoordinatorLayout not scrolling properlyCoordinatorLayout 无法正确滚动
【发布时间】:2016-05-02 23:06:34
【问题描述】:

我正在尝试实现一个主 Activity,它由一个 appbar 和一个交错的“文章”网格组成

我的 appbar 没有任何菜单按钮,只有一个包含应用品牌的 imageView。

我实现了一个协调器布局,因为我想在滚动网格时实现以下行为:

  • 112dp 高的应用栏应该折叠,直到达到 minHeight 属性中描述的高度。 recyclerview 元素应该在它下面通过。图片应缩小约 20%,以使视觉效果更具冲击力。

由于某种原因,当我滚动 recyclerview 时,appbar 保持在其原始位置并且不会折叠。

这是我的 xml 文件:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/toolbar_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?colorPrimary">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:layout_marginLeft="@dimen/list_toolbar_side_margin"
            android:layout_marginRight="@dimen/list_toolbar_side_margin"
            android:layout_width="match_parent"
            android:layout_height="112dp"
            android:minHeight="?actionBarSize"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:src="@drawable/logo"
                android:contentDescription="@string/app_name" />

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:paddingTop="116dp"
            android:paddingLeft="@dimen/list_side_margin"
            android:paddingRight="@dimen/list_side_margin"
            android:paddingBottom="28dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </android.support.v4.widget.SwipeRefreshLayout>


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

你能帮帮我吗?

P.S.:是否有任何在线资源可以教您如何实现材料设计滚动技术?尤其是以下链接中的最后一个:

http://www.google.com/design/spec/patterns/scrolling-techniques.html?utm_campaign=io15&utm_source=dac&utm_medium=blog#scrolling-techniques-scrolling

【问题讨论】:

  • 我跟踪了这​​个问题,但它并没有解决我的具体问题。如果有人知道其他可能的原因,请告诉我
  • 您找到解决方案了吗?

标签: android android-coordinatorlayout android-appbarlayout


【解决方案1】:

你可以尝试让Parent layout ScrollView Behaviour

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    相关资源
    最近更新 更多