我正在使用带有ViewPager的NestedScrollView。 NestedScrollView内部有一个LinearLayout,其中包含一些TextView、TabLayout和ViewPager。 TextView占用大部分空间,ViewPager只留下一点空间。 ViewPager使用两个片段,其中一个片段中有几个TextView和ImageViews,另一个片段中有一个RecyclerView。
当我将ViewPager的高度设置为
当我将ViewPager的高度设置为1000dp时,例如,我可以向下滚动第一个片段,但第二个片段仍然在小ViewPager内滚动。并且在我滚动带有RecyclerView的片段后,第一个片段中的滚动不再起作用。
如何解决滚动问题并使ViewPager与
以下是我的代码:
当我将ViewPager的高度设置为
WRAP_CONTENT
时,它只占用剩余的空间,我无法滚动以查看第一个片段的其余部分,并且第二个片段在小ViewPager内滚动。当我将ViewPager的高度设置为1000dp时,例如,我可以向下滚动第一个片段,但第二个片段仍然在小ViewPager内滚动。并且在我滚动带有RecyclerView的片段后,第一个片段中的滚动不再起作用。
如何解决滚动问题并使ViewPager与
WRAP_CONTENT
一起工作?以下是我的代码:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_scrollFlags="scroll"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/mainBackground"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOME TEXT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOME TEXT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOME TEXT" />
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>