ViewPager in a NestedScrollView

前端 未结 19 1994
面向向阳花
面向向阳花 2020-11-27 10:08

I need to create an interface like Google Newsstand which is a sort of ViewPager (horizontal scroll) over a collapsing header (vertical scroll). One of my requirements is to

相关标签:
19条回答
  • 2020-11-27 10:44

    Actually the NestedScrollView doesn't need to to be direct sibling of CollapsingToolbarLayout in CoordinatorLayout. I have achieved something realy bizzare. The appbar_scrolling_view_behavior works in 2 nested fragments.

    My activity layout:

    <android.support.design.widget.CoordinatorLayout>
    
        <android.support.design.widget.AppBarLayout>
    
                <android.support.design.widget.CollapsingToolbarLayout>
    
                    <include
                        layout="@layout/toolbar"/>
    
                </android.support.design.widget.CollapsingToolbarLayout>
    
        </android.support.design.widget.AppBarLayout>
    
        <FrameLayout
            android:id="@+id/container"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    
    </android.support.design.widget.CoordinatorLayout>
    

    In the "container" frameLayout I have inflated this fragment:

    <android.support.constraint.ConstraintLayout>
    
        ... some content ...
    
        <android.support.v4.view.ViewPager/>
    
        ...
    
    </android.support.constraint.ConstraintLayout>
    

    And fragments inside that ViewPager looks like this:

    <RelativeLayout>
    
        <android.support.v7.widget.RecyclerView/>
    
        ....
    
    </RelativeLayout>
    

    Fact that NestedScrollView can be so deep in the CoordinatorLayout children hierarchy and scroll behaviors stil works did suprised me.

    0 讨论(0)
提交回复
热议问题