【发布时间】:2015-10-08 09:00:32
【问题描述】:
我正在使用带有 ViewPager 的 NestedScrollView。 NestedScrollView 内部有一个 LinearLayout,最后有一些 TextView、TabLayout 和 ViewPager。 TextViews 占据了大部分空间,而为 ViewPager 留下了一点空间。 ViewPager 使用两个 Fragment,其中一个有几个 TextViews 和 ImageViews,另一个 Fragment 有一个 RecyclerView。
当我将 ViewPager 的高度设置为 WRAP_CONTENT 时,它只占用了剩下的空间,我无法滚动查看第一个片段的其余部分,第二个片段在小 ViewPager 内滑动。
例如,当我将 ViewPager 的高度设置为 1000dp 时,我可以在第一个片段上向下滚动,但第二个片段仍在小 ViewPager 内滚动。在我使用 RecyclerView scoll 在第一个 Fragment 中滚动片段后不再工作。
如何解决滚动问题并使 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>
【问题讨论】:
-
嗨,你让这个工作了吗?我试过 fillViewport 但它会将嵌套滚动视图截断为视口高度,并且回收器是嵌套滚动的。通过禁用嵌套滚动,即使是nestedscrollview 也不会滚动(这很奇怪)。请分享如何,如果你能让它工作。
标签: android android-viewpager android-recyclerview