0
NestedScrollview内に3つのrecyclerviewがあり、3番目のリサイクルは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);
このリンクをクリックしてください: リンクのhttp://stackoverflow.com/questions/35746113/android-recycleview-inside-scrollview –
おかげで、それは私に次の例外を生成: 'java.lang.IndexOutOfBoundsException:無効な項目を位置0(0)。アイテム数:android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:4622)android.support.v7.widget.RecyclerView $ Recycler.getViewForPosition(RecyclerView.java:4617)at com.actvt .actvt.CustomLinearLayoutManager.measureScrapChild(CustomLinearLayoutManager.java:67)、com.actvt.actvt.CustomLinearLayoutManager.onMeasure(CustomLinearLayoutManager.java:30) ' – user1796260