【问题标题】:Scrollview inside ViewPagerFragment from NestedScrollview来自 NestedScrollview 的 ViewPagerFragment 内的滚动视图
【发布时间】:2018-12-16 04:58:06
【问题描述】:

所以我有一个使用 NestedScrollView 的 Activity,并且在 NestedScrollView 内部是一个 ViewPager。 该 ViewPAger 包含 2 个片段。一个在 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="" true 和 false,但从未得到想要的结果。

Fragment 的 ScrollView 和 RecyclerView 正在滚动,但我不想滚动它们,我想滚动 Activity 的 Nested ScrollVIew。

【问题讨论】:

  • 如果将 ScrollView 替换为 NestedScrollView 会发生什么?并在设置适配器之前设置recyclerView.setNestedScrollingEnabled(false);
  • 如果我将ScrollView 替换为NestedScrollView,那么只有片段布局在滚动而不是活动布局。如果我设置recyclerView.setNestedScrollingEnabled(false); 然后滚动不起作用但是当我设置recyclerView.setNestedScrollingEnabled(true); 然后recyclerView 正在滚动。但同样的问题,活动布局不滚动。

标签: android android-viewpager android-nestedscrollview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多