SwipeRefreshLayout from lib support. v21 does not work with static content

I am using SwipeRefreshLayout from the v21 support library. It works great with scrollable content like List or ScrollView, but it doesn't work with static layout:

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

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:gravity="center"
            android:text="Content"/>
    </ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

This code works well.

Video: Example

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:gravity="center"
            android:text="Content"/>
</android.support.v4.widget.SwipeRefreshLayout>

And this is not so.

Video: Example

Is it possible to work with skip content in SwipeRefreshLayout?

+4
source share
1 answer

Update:

This issue is now fixed in version 24.2.0 of the support library.


Original answer:

21 , , onTouchEvent() SwipeRefreshLayout onInterceptTouchEvent(). SwipeRefreshLayout , View. , , SwipeRefreshLayout 19.1.0 , 20.

https://code.google.com/p/android/issues/detail?id=87789

SwipeRefreshLayout onTouchEvent() onInterceptTouchEvent() , true:

public class FixedSwipeRefreshLayout extends SwipeRefreshLayout {
    public FixedSwipeRefreshLayout(Context context) {
        super(context);
    }

    public FixedSwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    private boolean handleTouch = true;
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        int action = MotionEventCompat.getActionMasked(ev);
        switch (action) {
            case MotionEvent.ACTION_DOWN:
                handleTouch = false;
                break;
            default:
                if (handleTouch) {
                    return super.onTouchEvent(ev);
                }
                handleTouch = onInterceptTouchEvent(ev);
                switch (action) {
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_CANCEL:
                        handleTouch = true;
                        break;
                }
                break;
        }
        return true;
    }
}
+9

Source: https://habr.com/ru/post/1568602/


All Articles