【问题标题】:Pass recyclerview swipe event to viewpager将 recyclerview 滑动事件传递给 viewpager
【发布时间】:2019-04-03 11:22:33
【问题描述】:

我在同一个 Activity 中有一个 ViewPager 和 RecyclerView,这两个视图重叠(RecyclerView 在前面,ViewPager 在后面)。当我在空白空间上滑动时,我的 ViewPager 滑动可以正常工作,但是当我在 RecyclerView 上滑动时,viewpager 滑动不起作用。我在 Recyclerview 中有按钮和搜索栏。我想将 RecyclerView 滑动事件传递给 viewpager(搜索栏除外)。那么我如何确定recylerview的seekbar是否被刷过?以及如何将 recylerview 的滑动事件传递给 viewpager。

我的布局:

<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/viewPager"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true" />

    <RelativeLayout
        android:id="@+id/imagesLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bottomRelativeLayout"
        android:layout_below="@+id/timerLayout"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="5dp"
        android:visibility="gone">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/myRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="5dp"
            android:clickable="true"
            android:fadingEdgeLength="30dp"
            android:focusable="true"
            android:gravity="center"
            android:horizontalSpacing="3dp"
            android:listSelector="@android:color/transparent"
            android:numColumns="3"
            android:overScrollMode="never"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingBottom="15dp"
            android:paddingTop="15dp"
            android:requiresFadingEdge="vertical"
            android:scrollbars="none" />


    </RelativeLayout>

还有我的java代码:

imagesRecyclerView = (RecyclerView) findViewById(R.id.myRecyclerView);
        int numberOfColumns = 3;
        imagesRecyclerView.setLayoutManager(new GridLayoutManager(context, numberOfColumns));
        imagesRecyclerView.getItemAnimator().setChangeDuration(0);
        imagesRecyclerView.setHasFixedSize(false);

【问题讨论】:

  • 如果我没记错的话:你可以从RecyclerView 和他的父母中删除clickable / focusable 属性+ 如果有设置,则从ItemView 中删除它们。现在你应该可以刷ViewPager了。
  • 但是RecylerView里面有button和seekbar。所以我想处理 RecyclerView 上的滑动事件,如果它不在 seekbar 上,我想传递给 viewpager。
  • 然后向我们展示 RecyclerView 项目布局

标签: android android-recyclerview android-viewpager swipe touch-event


【解决方案1】:

在您的回收站视图中删除

android:scrollbars="none"

【讨论】:

    猜你喜欢
    • 2015-10-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    相关资源
    最近更新 更多