Before digging into the code, I've already checked the following questions:
- How to use RecyclerView inside NestedScrollView?
- Recyclerview inside Nested Scrollview scroll but does not fast scroll like normal Recyclerview or Nested Scrollview
- RecyclerView inside a ScrollView/NestedScrollView does not scroll properly
None of the aforementioned questions has worked with me. The RecyclerView
is too laggy when scrolling.
I have a NestedScrollview
and a LinearLayout
as a main Layout for the NestedScrollview
. Layout's code is:
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:fbutton="http://schemas.android.com/apk/res-auto"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/frag_misc_rv_margin_top"
android:scrollbars="none"
android:nestedScrollingEnabled="false"
android:id="@+id/frag_showcase_promotion_recyclerview"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
The code is:
mPromotionsRv.setLayoutManager(new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false));
mPromotionsRv.setNestedScrollingEnabled(false);
mPromotionsAdapter = new ShowcasePromotionRvAdapter(getActivity(), mPromotionsItems);
mPromotionsAdapter.setOnItemClickListener(new ShowcasePromotionListener() {
@Override
public void onClick(View view, int position) {
ItemPromotion mPromotion = mPromotionsItems.get(position);
try{
recordPromotionClick(mPromotion.getId());
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(mPromotion.getPromotion_link())));
} catch (Exception e){
e.printStackTrace();
}
}
});
mPromotionsRv.setAdapter(mPromotionsAdapter);
SnapHelper snapHelperStart = new GravitySnapHelper(Gravity.START);
snapHelperStart.attachToRecyclerView(mPromotionsRv);
RecyclerView.ItemAnimator animator = mPromotionsRv.getItemAnimator();
if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }
wrap_content
withRecyclerView
is always going to risk using too many resources. – Ben P.