Pass touch event from recycler to its parent LinearLayout

java android android-layout animation android-recyclerview

91 观看

1回复

838 作者的声誉

I have something like this :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="cntxt">


<LinearLayout
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <!-- Title -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:gravity="center"
        android:padding="20dp"
        android:text="@string/title"
        android:textColor="@android:color/white"
        android:textSize="17sp" />

        <!-- Recycler -->
        <CustomRecyclerView
            android:id="@+id/main_activity_rv"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:scrollingCache="false" />
</LinearLayout>

When the layout is scrolled to top, when the user makes a similar to "swipe to refresh" move with his finger, I need to make a translate animation on Y axes. In other words, I need to follow the move of the finger the whole recycler if the recycler is on top.

I tried to attach an onTouch listener to the recycler but the inner scroll of the recycler makes the situation unclear. Any ideas to achieve this animation?

If I attach the onTouchListener to the main_layout and do the fling from the iner textview, the animation plays normally. But when I touch the recycler nothing happens (except of recycler's inner scrolls) Thank you in advance.

作者: karvoynistas 的来源 发布者: 2017 年 12 月 27 日

回应 1


0

4121 作者的声誉

Make the outer most layer a

SwipeRefreshLayout 

Instead of a relative layout. This will give you the pull to refresh functionality any way.

Also note, under the swipe layout mentioned, there can only be one direct child view so what ever you put... Make sure to put it in the linear layout you have.

You can attach an OnRefreshListener to listen to the pull of the refresh layout.

作者: Kushan 发布者: 2017 年 12 月 27 日
32x32