viewpager+fragment+recyclerview sliding freeze/sliding conflict (non-preloading problem)

Problem Description

First of all, the sliding conflicts I want to record are not horizontal and vertical sliding conflicts, but horizontal and horizontal sliding conflicts! ! ! !

To put it simply, a viewpager+fragment+recyclerview structure is used in the project. The recyclerview is placed in the fragment, and then the viewpager is used to switch the fragments.

The recyclerview in the project does not need to slide. The reason why the recyclerview is selected is that it is very easy to use the recyclerview to arrange the items when they are passed in one by one.

Then the problem came, when I finished this, I swipe my viewpager and found that each page needs to be swipe twice before I can swipe over. When I swipe for the first time, it shows that I swipe to the end, and then I swipe to succeed. . (they all slide horizontally)

So the problem is that the sliding of recyclerview conflicts with the sliding of viewpager, so here I need to disable the sliding of recyclerview (I don’t need it anyway)

Here are a few methods I've tried that didn't work, but are listed here anyway

1. Modify the xml file

Find the xml file of recyclerview, and add a sentence of android:overScrollMode="never"
as shown below

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"/>

After setting it in my project, the white edge that prompts the end will no longer appear when sliding, but it still needs to be swiped twice to turn the page

2. Set recyclerview

just one word

recyclerview.setNestedScrollingEnabled(false)

This is what I saw in a blog, the original address https://blog.csdn.net/maxiaoteng_321519/article/details/76639366
Finally, the blogger also added a further description

"I tried it today. setNestedScrollingEnabled(false) is only applicable to subclasses of NestedScrollingChild. Simply put, it is only applicable to nested layouts (the nested layout was just used a few days ago). If you don't nest, look at other people answer

solution

Hahaha the main event is here, but it is actually very simple, just one sentence linearLayoutManager.setSmoothScrollbarEnabled(false);
the code is as follows:

        RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.icon_recyclerview);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //禁用滑动
        linearLayoutManager.setSmoothScrollbarEnabled(false);
        
        recyclerView.setLayoutManager(linearLayoutManager);
        RecyclerViewIconAdapter recyclerViewIconAdapter = new RecyclerViewIconAdapter(for_mApps,getActivity());
        recyclerView.setAdapter(recyclerViewIconAdapter);

Before setting the layoutmanager for the recyclerview, set the setSmoothScrollbarEnabled of the layoutmanager to false and it will be ok, the problem is solved

Guess you like

Origin blog.csdn.net/qq_33445510/article/details/82787936