2015-10-11 18 views
6

मुझे ReapserView में स्क्रॉलिंग के साथ कुछ समस्या है, नेस्लेस्क्रॉलव्यू के भीतर, CollapsingToolbarLayout के बगल में।
समस्या RecyclerView स्क्रॉल और Collapsing नहीं है ToolbarLayout विस्तार/संकुचित नहीं करता है। यहां एक्सएमएल है:रीसाइक्लर नेस्टेडस्क्रॉल व्यू लेआउट के भीतर देखें स्क्रॉलिंग

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawerLayout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layoutDirection="rtl" 
tools:context=".MainActivity"> 

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/rootLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

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

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbarLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:elevation="12dp" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginEnd="64dp" 
      app:expandedTitleTextAppearance="@color/trans" 
      app:layout_scrollFlags="scroll|enterAlwaysCollapsed"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:src="@drawable/header" /> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:src="@drawable/header_basij" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       android:minHeight="?attr/actionBarSize" 
       android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
       app:layout_collapseMode="pin" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 

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

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

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fadeScrollbars="true" 
     android:fillViewport="true" 
     android:scrollbarDefaultDelayBeforeFade="1000" 
     android:scrollbarFadeDuration="2000" 
     android:scrollbars="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

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

      <pl.droidsonroids.gif.GifImageView 
       android:id="@+id/pbar" 
       android:layout_width="100dp" 
       android:layout_height="30dp" 
       android:layout_gravity="center" 
       android:layout_marginTop="8dp" 
       android:background="@color/trans" 
       android:src="@drawable/loader" 
       /> 

      <LinearLayout 
       android:id="@+id/interneterror" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="20dp" 
       android:orientation="vertical" 
       android:visibility="visible"> 

       <TextView 
        android:id="@+id/errorhandler" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:text="خطا در اتصال به اینترنت" 
        android:textColor="#212121" /> 

       <Button 
        android:id="@+id/tryagainme" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center" 
        android:text="سعی دوباره" 
        android:textColor="@color/colorPrimary" /> 

      </LinearLayout> 

      <android.support.v7.widget.RecyclerView 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/recyclerView" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:fadeScrollbars="true" 
       android:layoutDirection="rtl" 
       android:scrollbars="vertical" 
       tools:context=".MainActivity"/> 

     </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 

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

<android.support.design.widget.NavigationView 
    android:id="@+id/navigation" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:layoutDirection="rtl" 
    app:headerLayout="@layout/navigation_header" 
    app:itemIconTint="@color/nav_item_icon_tint_color" 
    app:itemTextColor="@color/nav_item_text_color" 
    app:menu="@menu/navigation_menu" /> 

</android.support.v4.widget.DrawerLayout> 

सहायता के लिए धन्यवाद।

+0

संभावित डुप्लिकेट [NestedScrollView अंदर RecyclerView का उपयोग कैसे करें?] (Http://stackoverflow.com/questions/31000081/how- के लिए उपयोग-recyclerview-अंदर-nestedscrollview) –

उत्तर

4

आप कॉल करने के लिए "recyclerView.setNestedScrollingEnabled(false)"

+0

इस सही जवाब – Sree

+0

@Ram 'recyclerView.setNestedScrollingEnabled (गलत)' केवल API स्तर 21 और इसके बाद के संस्करण में काम कर सकते है। इसलिए निचले एपिस –

0

कारण यह है कि NestedScrollView AppBarLayout.Behavour वर्ग फोन नहीं करता है जब यह recyclerview से स्क्रॉल ईवेंट प्राप्त की जरूरत है। यानी, जब रीसाइक्लिंगव्यू में स्क्रॉल होता है, तो रीसाइक्लर्व व्यू/स्क्रॉल प्रगति को NestedScrollView पर भेजता है। NestedScrollView स्क्रॉल ईवेंट प्राप्त करता है लेकिन इसके साथ कुछ भी नहीं करता है।

nestedscrollview वर्ग के अंदर

@Override 
public void onNestedpreScroll(View target,int dx, int dy, int[] consumed){ 
     //Do nothing 
} 

इस पर काबू पाने और appbarlayout कर सिर्फ इतना है कि NestedScrollView फैली एक कस्टम वर्ग बनाने के विस्तृत/संक्षिप्त करें recyclerview स्क्रॉल जब, और उपरोक्त विधि और कॉल विधि dispatchNestedPreScroll() जो appbarlayout को सूचित करने के लिए overide स्क्रॉल घटना का और इसे प्रतिक्रिया दें।

public class CustomNestedScrollView extends NestedScrollView{ 

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

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

    public CustomNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { 
    super(context, attrs, defStyleAttr); 
    } 

    @Override 
    public void onNestedPreScroll(View target, int dx, int dy, int[] consumed){ 
    dispatchNestedPreScroll(dx,dy,consumed,null); 
    } 
} 

और फिर अपने layout.xml में इस वर्ग का उपयोग

<com.my.package.CustomNestedScrollView 
    android:id="@+id/scroll" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    /* 
     CONTENT 
    */ 

</LinearLayout> 
की
+0

के लिए समाधान नहीं है यह मेरे लिए काम नहीं करता !! इसके अलावा इस overcoding का एक सा प्रतीत हो रहा है इस परिसर में (कम से कम मेरे लिए) है। मैंने यह सब किए बिना हल किया .. मैं आपको पाठकों को आसान तरीके खोजने के लिए प्रोत्साहित करता हूं। क्योंकि वहाँ हैं! – eRaisedToX

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