ScrollView inside ViewPager does not scroll on Android 4.x

Deadly 提交于 2019-12-05 12:58:26
Frank

Solved! I had exactly the same problem. You are probably using a PageTransformer ViewPager animation.

Disabling the custom page transformer for < Android 4.1 solved it:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        // there are problems with this on 4.0.3, probably also on 4.1
        viewPager.setPageTransformer(true, new DepthPageTransformer());
    }

Your post and research saved me a lot of time, thank you.

OTHER SOLUTION:

If you like your animation, you can also try changing your DepthPageTransformer to this: https://stackoverflow.com/a/28214802/1310343c

You are right, the 2 scrollable controls are competing with each other.

Use a NestedScrollView from the Support Library instead. It is designed to get around problems of this type.

It has many enhancements that lets it work with other scrollable controls, including the ViewPager, RecyclerView (as long as you call .setNestedScrolling(true)) and CoordinatorLayout.

Based on the above, I have been using this new class in all instances, and the scrolling within scrolling has been working perfectly. Our product is live with perfectly working NestedScrollView controls inside a ViewPager, some with embedded RecyclerView lists inside them as well.

For me this setup worked: I have a Coordinator layout which has below nested scrollview

 <android.support.v4.widget.NestedScrollView
    android:layout_marginTop="8dp"
    android:fillViewport = "true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <include layout="@layout/content_app_bar_search_patient_module"/>

</android.support.v4.widget.NestedScrollView>

and <include layout="@layout/content_app_bar_search_patient_module"/>has a viewpager which has fragment which contains again a nested scrollview

<android.support.v4.widget.NestedScrollView 

xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
.
.
.
    </android.support.v4.widget.NestedScrollView>

Your ScrollView must have match_parent height and first child of scrollview ( LinearLayout ) must have wrap_content height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!