NestedScrollview的ViewPagerFragment内部的Scrollview

时间:2018-07-08 07:31:10

标签: android android-viewpager android-nestedscrollview

所以我有一个使用NestedScrollView的Activity,并且在NestedScrollView内部是一个ViewPager。 该ViewPAger包含2个片段。一个在scrollview中具有布局,另一个在recyclerView中。

但是两个片段都没有滚动(scrollview和recyclerview都没有。)

活动XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:id="@+id/ll_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:background="@color/colorPrimary"
                android:orientation="vertical">

               // Some Textview & imagehview here

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/ll_header"
                android:orientation="vertical">

                <com.ogaclejapan.smarttablayout.SmartTabLayout
                    android:id="@+id/movietab"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_40sdp"
                    android:background="@color/colorAccent"
                    android:paddingBottom="@dimen/_2sdp"
                    app:stl_defaultTabTextColor="@color/white"
                    app:stl_defaultTabTextHorizontalPadding="@dimen/_20sdp"
                    app:stl_distributeEvenly="true"
                    app:stl_indicatorColor="@color/white"
                    app:stl_indicatorCornerRadius="1dp"
                    app:stl_indicatorInterpolation="smart"
                    app:stl_indicatorThickness="3dp"
                    app:stl_underlineColor="@color/transparent" />

                <android.support.v4.view.ViewPager
                    android:id="@+id/mViewpager"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@+id/movietab" />

            </RelativeLayout>

        </RelativeLayout>

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

</android.support.design.widget.CoordinatorLayout>

Fragment1 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color1">

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true">

        <LinearLayout
            android:id="@+id/llInfo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            //Inner Layout


        </LinearLayout>

    </ScrollView>

</RelativeLayout>

Fragment2 XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/llCasting"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.movies.MovieCastFragment">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvCast"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />


</LinearLayout>

我在每种布局上都尝试android:nestedScrollingEnabled=""是非题,但从未得到想要的结果。

Fragment的ScrollView和RecyclerView杂乱无章,但我不想滚动它们,我想滚动Activity的Nested ScrollVIew。

1 个答案:

答案 0 :(得分:0)

您的ViewPager的高度应该设置为wrap_content,嵌套的滚动应该设置为false,以便父级NestedScrollView负责滚动。