recycelerview项目onclick窃取appbarlayout滚动

时间:2016-12-11 16:25:36

标签: android android-recyclerview android-appbarlayout

我有一个具有多视图类型的recyclerview,有些视图包含带onclick的项目。 当我在recyclerview中滚动如果触摸外部可点击项目appbarlayout hide / show,但是如果我将我的手指放在可点击项目上以滚动recyclelerview它将窃取焦点并且appbarlayout不隐藏/显示

活动

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <ViewSwitcher
        android:id="@+id/vs"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_scrollFlags="scroll|enterAlways|snap">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|snap"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <TextView
                android:id="@+id/toolbar_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="right|center_horizontal"
                android:ellipsize="end"
                android:maxLines="1"
                android:paddingRight="0dp"
                android:textColor="@color/md_white_1000"
                android:textSize="16dp" />
        </android.support.v7.widget.Toolbar>

        <RelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="56dp"
            android:background="@color/md_white_1000"
            android:elevation="2dp"
            android:fitsSystemWindows="true">

        </RelativeLayout>

    </ViewSwitcher>


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

<include layout="@layout/content_activity_main" />

使用recyclerview进行分段

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:clipToPadding="false"
    app:layout_collapseMode="parallax"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/ll_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            style="?android:attr/progressBarStyle"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical|center_horizontal"
            android:layout_margin="25dp" />
    </LinearLayout>

    <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rv_dashboard"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layoutDirection="rtl"/>
</LinearLayout>

1 个答案:

答案 0 :(得分:0)

如果添加.setNestedScrollingEnabled(false);进入内部回收者视图将会完成!