6

क्या किसी ने अभी भी 23.2 पर एक साथ काम करने के लिए रीसाइक्लिंग, ऐपबारलेआउट्स और स्वाइप रिफ्रेश लेआउट प्राप्त करने का कोई तरीका निकाला है? मैं एक सुंदर मानक विधि का उपयोग कर रहा हूं जो मुझे लगता है, लेकिन swiperefreshlayout रीसाइक्लिंग व्यू को स्थानांतरित करने का प्रयास करते समय स्क्रॉल इशारा को पकड़ता रहता है।समर्थन लाइब्रेरी का उपयोग कर रीसाइक्लिंगव्यू और स्वाइप रीफ्रेशआउटआउट 23.2.0

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:theme="?attr/toolbar_theme" 
      app:layout_scrollFlags="scroll|enterAlways" 
      android:elevation="4dp" /> 
    </android.support.design.widget.AppBarLayout> 
    <FrameLayout 
     android:id="@+id/fragment_container" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!--fragment goes here --> 
    </FrameLayout> 
</android.support.design.widget.CoordinatorLayout> 
साथ

अंदर निम्नलिखित यह

<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_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?attr/window_background"> 
<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ProgressBar 
     android:id="@+id/progress_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     style="@style/Widget.AppCompat.ProgressBar.Horizontal" 
     android:layout_marginTop="-4dp" 
     android:layout_marginBottom="-8dp" 
     android:elevation="17dp" 
     android:indeterminate="true" 
     android:visibility="invisible" /> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scrollbars="vertical" /> 
</FrameLayout> 
</android.support.v4.widget.SwipeRefreshLayout> 

उत्तर

6

attrs.xml

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="ImprovedSwipeLayoutAttrs"> 
     <attr name="scrollableChildId" format="reference" /> 
    </declare-styleable> 
</resources> 

layout.xml

<in.nerd_is.inactive_weibo.ui.ImprovedSwipeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:fab="http://schemas.android.com/apk/res-auto" 
    xmlns:isl="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/swipe_container" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/md_blue_grey_50" 
    isl:scrollableChildId="@+id/list_statuses" 
    tools:context="in.nerd_is.inactive_weibo.ui.StatusesFragment" > 

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

     <ListView 
      android:id="@+id/list_statuses" 
      android:minHeight="?android:attr/listPreferredItemHeight" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:paddingTop="12dp" 
      android:paddingBottom="12dp" 
      android:paddingLeft="8dp" 
      android:paddingRight="8dp" 
      android:clipToPadding="false" 
      android:divider="@android:color/transparent" 
      android:dividerHeight="12dp"/> 

     <com.melnykov.fab.FloatingActionButton 
      android:id="@+id/button_floating_action" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="bottom|right" 
      android:layout_margin="16dp" 
      android:src="@drawable/ic_md_create" 
      fab:fab_colorNormal="@color/md_blue_400" 
      fab:fab_colorPressed="@color/md_blue_grey_500"/> 
    </FrameLayout> 

</in.nerd_is.inactive_weibo.ui.ImprovedSwipeLayout> 

ImprovedSwipeLayout.java

+०१२३५१६४१०
public class ImprovedSwipeLayout extends SwipeRefreshLayout { 

    private static final String TAG = ImprovedSwipeLayout.class.getCanonicalName(); 
    private int mScrollableChildId; 
    private View mScrollableChild; 

    public ImprovedSwipeLayout(Context context) { 
     this(context, null); 
    } 

    public ImprovedSwipeLayout(Context context, AttributeSet attrs) { 
     super(context, attrs); 

     TypedArray a = context.obtainStyledAttributes(
       attrs, R.styleable.ImprovedSwipeLayoutAttrs); 
     mScrollableChildId = a.getResourceId(R.styleable.ImprovedSwipeLayoutAttrs_scrollableChildId, 0); 
     mScrollableChild = findViewById(mScrollableChildId); 
     a.recycle(); 
    } 

    @Override 
    public boolean canChildScrollUp() { 
     ensureScrollableChild(); 

     if (android.os.Build.VERSION.SDK_INT < 14) { 
      if (mScrollableChild instanceof AbsListView) { 
       final AbsListView absListView = (AbsListView) mScrollableChild; 
       return absListView.getChildCount() > 0 
         && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0) 
         .getTop() < absListView.getPaddingTop()); 
      } else { 
       return mScrollableChild.getScrollY() > 0; 
      } 
     } else { 
      return ViewCompat.canScrollVertically(mScrollableChild, -1); 
     } 
    } 

    private void ensureScrollableChild() { 
     if (mScrollableChild == null) { 
      mScrollableChild = findViewById(mScrollableChildId); 
     } 
    } 

} 

यह एक दृश्य का विस्तार SwipeRefreshLayout और कस्टम canChildScrollUp बनाएं से http://nerd-is.in/2014-09/add-multi-child-view-in-swiperefreshlayout/

है।

2

23.2.0 पर अपडेट करने के बाद issue का सामना करना पड़ा। यह एक पुरानी नई बग है जिसे 23.1.1 में तय किया गया था और 23.2.0 में फिर से दिखाई देता है।

मेरे मामले में मैं 23.1.1 पर डाउनग्रेड करता हूं और हमेशा के लिए ठीक है। तो हमें SwipeRefreshLayout ओवरराइडिंग के साथ libs के नए संस्करण की प्रतीक्षा करनी चाहिए या workarounds का उपयोग करना चाहिए। RecyclerView v23.2.0 - doesn't play nicely with SwipeRefreshLayout

5

आप एक दृश्य है कि ScrollingView को लागू नहीं करता है या SwipeRefreshLayout में एक AbsListView नहीं है रखते हैं, SwipeRefreshLayout#canChildScrollUp() हमेशा गलत रिटर्न:


यहाँ गूगल बगट्रैकर के लिए लिंक है।

तो का उपयोग करके एक FrameLayoutSwipeRefreshLayout के अंदर आप दो मुद्दे हैं:

  1. SwipeRefreshLayout वंशज विचारों का नेस्टेड स्क्रॉल संचालन को स्वीकार नहीं करता (SwipeRefreshLayout#onStartNestedScroll(View, View, int) देखें)। इससे CoordinatorLayout/AppBarLayout के साथ समस्याएं उत्पन्न होती हैं।

  2. SwipeRefreshLayout के रूप में अपनी बच्चे ऊपर स्क्रॉल नहीं कर सकते हैं या वहाँ प्रगति में कोई नेस्टेड पुस्तक है स्पर्श इवेंट में ही रूप में लंबे समय संभालती (SwipeRefreshLayout#onInterceptTouchEvent(MotionEvent) और SwipeRefreshLayout#onTouchEvent(MotionEvent) देखें)। इसका मतलब है कि स्पिनर प्रदर्शित होता है जब "नीचे जाने से स्पर्श करें"।

आप अपनी खुद की SwipeRefreshLayout, जो SwipeRefreshLayout#onStartNestedScroll(View, View, int) अधिलेखित कर देता है का उपयोग करके इसे ठीक कर सकते हैं। भले ही प्रत्यक्ष बच्चे दृश्य ऊपर स्क्रॉल नहीं कर सकते हैं इस तरह नेस्ट स्क्रॉल स्वीकार कर रहे हैं: यदि आप 23.1.1 में SwipeRefreshLayout के कोड आप देखेंगे देखो

public class SwipeRefreshLayout extends android.support.v4.widget.SwipeRefreshLayout { 

    public SwipeRefreshLayout(Context context) { 
     super(context); 
    } 

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

    @Override 
    public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) { 
     return isEnabled() 
       && !isRefreshing() 
       && (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0; 
    } 
} 

Btw, कि canChildScrollUp() चेक था हटा दिया गया लेकिन 23.2.0 में फिर से जोड़ा गया था।मैंने !mReturningToStart के लिए चेक भी हटा दिया, क्योंकि mReturningToStart हमेशा false है।

+0

आपको इस कार्यवाही को अब लागू करने की आवश्यकता नहीं है, क्योंकि यह 23.3.0 में तय है। – segoh

संबंधित मुद्दे