Android ScrollView nested recyclerview causes slide lag problem resolution

Source: Internet
Author: User

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
  1. Linearlayoutmanager Linearlayoutmanager = new Linearlayoutmanager (Getactivity (), linearlayoutmanager.vertical, false) {  
  2. @Override
  3. Public Boolean canscrollvertically () {
  4. return false;
  5. }
  6. };
  7. Recyclerview.setlayoutmanager (Linearlayoutmanager);
  8. 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
    1. Linearlayoutmanager = New Linearlayoutmanager (context) {
    2. @Override
    3. Public Boolean canscrollvertically () {
    4. return false;
    5. }
    6. };

The other is to rewrite the LayoutManager, using grid mode to illustrate:

[Java]View PlainCopy
  1. Public class Scrollgridlayoutmanager extends Gridlayoutmanager {
  2. Private Boolean isscrollenabled = true;
  3. Public Scrollgridlayoutmanager (context context, AttributeSet attrs, int defstyleattr, int defstyleres) { /c11>
  4. Super (context, Attrs, defstyleattr, defstyleres);
  5. }
  6. Public Scrollgridlayoutmanager (context context, int spancount) {
  7. Super (context, spancount);
  8. }
  9. Public Scrollgridlayoutmanager (context context, int spancount, int orientation, boolean reverselayout) {  
  10. Super (context, spancount, orientation, reverselayout);
  11. }
  12. public void Setscrollenabled (boolean flag) {
  13. this.isscrollenabled = flag;
  14. }
  15. @Override
  16. Public Boolean canscrollvertically () {
  17. //similarly can customize "canscrollhorizontally ()" for managing horizontal scroll
  18. return isscrollenabled && super.canscrollvertically ();
  19. }
  20. }

Android ScrollView nested recyclerview causes sliding lag problem resolution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.