【问题标题】:Android Design Library: SwipeRefreshLayout don't detect swipe over CollapsingToolbarLayoutAndroid 设计库:SwipeRefreshLayout 不检测在 CollapsingToolbarLayout 上的滑动
【发布时间】:2015-08-18 10:16:20
【问题描述】:

在我的应用程序中,我在 SwipeRefreshLayout 内部使用 CollapsingToolbarLayout 跟随 NestedScrollView。我对SwipeRefreshLayout 的要求是检测从CollapsingToolbarLayout 的滑动,但它从NestedScrollView 检测到并忽略CollapsingToolbarLayout 上的滑动。这是我的 XML:

<?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.support.design.widget.CoordinatorLayout
        android:id="@+id/rootLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.SwipeRefreshLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/swipe"
            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/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="256dp"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsingToolbarLayout"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <ImageView
                        android:id="@+id/profilePic"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:scaleType="centerCrop"
                        android:src="@drawable/ic_split_big_profile"
                        app:layout_collapseMode="parallax"
                        app:layout_collapseParallaxMultiplier="0.7" />

                    <include
                        android:id="@+id/toolbar_layout"
                        layout="@layout/toolbar"
                        android:layout_width="match_parent"
                        android:layout_height="?attr/actionBarSize"
                        app:layout_collapseMode="pin"
                        app:layout_scrollFlags="scroll|enterAlways" />

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

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

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="500dp">
                </RelativeLayout>
            </android.support.v4.widget.NestedScrollView>

            <android.support.design.widget.FloatingActionButton
                android:id="@+id/add_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|right"
                android:layout_marginBottom="@dimen/fab_margin_bottom"
                android:layout_marginRight="@dimen/fab_margin_right"
                android:onClick="addTxn"
                android:src="@drawable/ic_action_add_transaction_light"
                app:elevation="6dp"
                app:fabSize="normal" />

        </android.support.v4.widget.SwipeRefreshLayout>
    </android.support.design.widget.CoordinatorLayout>
</RelativeLayout>

有人用过这种东西吗?

【问题讨论】:

    标签: android android-layout swiperefreshlayout android-collapsingtoolbarlayout android-appbarlayout


    【解决方案1】:

    AppBarLayout docs 中所述,它必须是 CoordinatorLayout 的直接子代

    这种观点很大程度上依赖于在一个 协调器布局。如果您在不同的 ViewGroup,它的大部分功能都不起作用。

    因此,我不确定 SwipeToRefreshLayout 必须包含在哪里才能与 CollapsingToolbar 一起使用,因为 NestedScrollView 也必须是直接子级。

    这是another response,它有助于附加 SwipeRefreshLayout 并仅在 appBar 未折叠时激活它,但它们没有使用 NestedScrollView,这对我不起作用:(


    编辑我找到了解决问题的方法:我使用的 ListView,必须设置为嵌套滚动,而不是放在 NestedScrollView 中,或者替换为 RecycleView:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         listView.setNestedScrollingEnabled(true);
    }
    

    因此,您的问题的解决方案应该是将 NestedScrollView 包装在 SwipeRefreshLayout 内。

    【讨论】:

      猜你喜欢
      • 2015-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 2016-07-31
      相关资源
      最近更新 更多