Android-resolves an issue where viewpager is nested when it cannot slide in API 13 and the following versions

Source: Internet
Author: User

Through the analysis of Viewpager event processing, it is found that the key point to solve this problem is to determine whether the part that can be slid horizontally, that is, CanScroll (View, boolean, int, int, int) method

In this method, recursively determine whether the sub-view can slide horizontally, and in the last row to determine whether you can slide horizontally. The key point is to call the viewcompat.canscrollhorizontally (View, int) method to determine if you can swipe sideways. See the source of viewcompat.canscrollhorizontally (view, int) further

Different versions have different implementations

The ICS version overrides canscrollhorizontally (view, int), calls viewcompatics.canscrollhorizontally (view, int)

viewcompatics.canscrollhorizontally (view, int) calls the view new canscrollhorizontally (int) method

Hcviewcompatimpl inherits from Gbviewcompatimpl, without rewriting canscrollhorizontally (View, int) method

Gbviewcompatimpl inherits from Eclairmr1viewcompatimpl, without rewriting canscrollhorizontally (View, int) method

Eclairmr1viewcompatimpl inherits from Baseviewcompatimpl, without rewriting canscrollhorizontally (View, int) method

Baseviewcompatimpl canscrollhorizontally (View, int) method returns false directly

The above source analysis can be summed up in API14 above is called the View New canscrollhorizontally (int) method to determine, and in API13 and below the direct return of false, can be understood as unsupported.

So this is no solution, of course not. Since Viewpager can slide normally above API14 then it is necessary to rewrite the canscrollhorizontally (int) method to view Viewpager's canscrollhorizontally (int) Method source finds that this method does not have version compatibility issues, and can be called directly on API13 and the following versions. The solution is to inherit the Viewpager rewrite CanScroll (View, boolean, int, int, int) method and call canscrollhorizontally (int) directly, as follows:

Read more about my open source project Compatviewpager Https://github.com/xiaopansky/CompatViewPager

Android-resolves an issue where viewpager is nested when it cannot slide in API 13 and the following versions

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.