2016-05-23 96 views
0

我在nestedscrollview中有三个recyclerview,我需要第三个继续循环,就像他不在nestedscrollview中一样。 这一切都很好,除了回收功能丢失。Android如何让RecyclerView在ScrollView里面循环使用

这里是我的xml:

 <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/scroll_discovery" 
     android:fillViewport="true" 
     android:fitsSystemWindows="true" 
     > 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      > 
      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/category_recycler"/> 
      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/category_recycler" 
       android:id="@+id/user_recycler"/> 
      <android.support.v7.widget.RecyclerView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/user_recycler" 
       android:id="@+id/experiences"/> 
     </RelativeLayout> 
    </android.support.v4.widget.NestedScrollView> 

这里是java部分

experienceRecycler=(RecyclerView)findViewById(R.id.experiences); 
    experienceRecycler.setHasFixedSize(true); 
    mLayoutManager =new LinearLayoutManager(this) { 
     @Override 
     public boolean canScrollVertically() { 
      return false; 
     } 
    }; 
    page= 1; 
    experienceRecycler.setLayoutManager(mLayoutManager); 
    experienceAdapter=new FeedCardAdapter(experiences,this,currentUser); 
    experienceRecycler.setAdapter(experienceAdapter); 
    /*experienceRecycler.addOnScrollListener(new RecyclerView.OnScrollListener() { 
     @Override 
     public void onScrollStateChanged(RecyclerView recyclerView, int newState) { 
      super.onScrollStateChanged(recyclerView, newState); 
     } 

     @Override 
     public void onScrolled(RecyclerView recyclerView, int dx, int dy) { 
      super.onScrolled(recyclerView, dx, dy); 
      feedCardAdapter.setScrolled(true); 
     } 
    });*/ 

    categoryRecycler=(RecyclerView)findViewById(R.id.category_recycler); 
    categoryRecycler.setLayoutManager(new LinearLayoutManager(this){ 
     @Override 
     public boolean canScrollVertically() { 
      return false; 
     } 
    }); 
    categoryAdapter=new CategoryAdapter(this,categories); 
    categoryRecycler.setHasFixedSize(true); 
    categoryRecycler.setAdapter(categoryAdapter); 

    userRecycler=(RecyclerView)findViewById(R.id.user_recycler); 

    userRecycler.setLayoutManager(new LinearLayoutManager(this){ 
     @Override 
     public boolean canScrollVertically() { 
      return false; 
     } 
    }); 
    userAdapter=new UserAdapter(this,users); 
    userRecycler.setAdapter(userAdapter); 
    userRecycler.setHasFixedSize(true); 
+0

请点击此链接: http://stackoverflow.com/questions/35746113/android-recycleview-inside-scrollview –

+0

感谢您的链接,但它产生了我以下异常: 'java.lang.IndexOutOfBoundsException:无效项位置0(0)。在android.support.v7.widget.RecyclerView上的Item count:0在android.support.v7.widget.RecyclerView处的$ Recycler.getViewForPosition(RecyclerView.java:4622)$ com.actvt处的Recycler.getViewForPosition(RecyclerView.java:4617) .actvt.CustomLinearLayoutManager.measureScrapChild(CustomLinearLayoutManager.java:67)at com.actvt.actvt.CustomLinearLayoutManager.onMeasure(CustomLinearLayoutManager.java:30)' – user1796260

回答

0

我finaly由我自己找到解决方案。 我刚刚有一个高度,我想继续回收recyclerview。

+0

您是否设置了固定高度? – superuserdo