A relatively long interface is generally scrollview nested recyclerview to solve. But such UI is not what our developers want to see, After nesting. Because ScrollView and Recyclerview are both slide controls. There will be a bit of sliding on the collision. Cause sliding up some of the Dayton. This time. Let's rewrite the LayoutManager, please.
For example:
[Java]View PlainCopy
- Linearlayoutmanager Linearlayoutmanager = new Linearlayoutmanager (Getactivity (), linearlayoutmanager.vertical, false) {
- @Override
- Public Boolean canscrollvertically () {
- return false;
- }
- };
- Recyclerview.setlayoutmanager (Linearlayoutmanager);
- Recyclerview.setadapter (Tempcommonadapter);
So, no sliding of Recyclerview is allowed. It will be as smooth as ever.
Problem phenomenon:
When an interface has multiple Recyclerview or other content that is more than one screen, you need to scroll up and down, you will need to nest a scrollview outside, but the sliding process is not very smooth, there is a feeling of lag.
Solution:
Recyclerview is forbidden to slide.
The simplest and most convenient way is
[Java]View PlainCopy
- Linearlayoutmanager = New Linearlayoutmanager (context) {
- @Override
- Public Boolean canscrollvertically () {
- return false;
- }
- };
The other is to rewrite the LayoutManager, using grid mode to illustrate:
[Java]View PlainCopy
- Public class Scrollgridlayoutmanager extends Gridlayoutmanager {
- Private Boolean isscrollenabled = true;
- Public Scrollgridlayoutmanager (context context, AttributeSet attrs, int defstyleattr, int defstyleres) { /c11>
- Super (context, Attrs, defstyleattr, defstyleres);
- }
- Public Scrollgridlayoutmanager (context context, int spancount) {
- Super (context, spancount);
- }
- Public Scrollgridlayoutmanager (context context, int spancount, int orientation, boolean reverselayout) {
- Super (context, spancount, orientation, reverselayout);
- }
- public void Setscrollenabled (boolean flag) {
- this.isscrollenabled = flag;
- }
- @Override
- Public Boolean canscrollvertically () {
- //similarly can customize "canscrollhorizontally ()" for managing horizontal scroll
- return isscrollenabled && super.canscrollvertically ();
- }
- }
Android ScrollView nested recyclerview causes sliding lag problem resolution