【发布时间】:2018-02-28 19:54:08
【问题描述】:
这感觉很简单,但不知何故我被卡住了。该视图不允许我滚动它。就好像在ViewPager 中膨胀的片段的高度没有被计算出来。搜索 SO 建议我需要编写自己的 ViewPager 并覆盖 onMeasure(),但我不敢相信我会为了这么简单的事情走那么远。
这是我的布局,为方便起见进行了一些简化。 ViewPager 填充了占据屏幕(垂直)之外空间的片段。尽管如此,屏幕上的任何内容都无法滚动。这是为什么呢?
<ScrollView
android:id="@+id/scroll_view"
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:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/header_image_view"
android:layout_width="0dp"
android:layout_height="170dp"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/title_text_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/header_image_view"/>
<Button
android:id="@+id/resume_training_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/title_text_view"/>
<android.support.design.widget.TabLayout
android:id="@+id/lesson_table_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:layout_constraintTop_toBottomOf="@id/resume_training_button">
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/lesson_table_layout">
</android.support.v4.view.ViewPager>
</android.support.constraint.ConstraintLayout>
</ScrollView>
这是一个示例视图。 Lorem ipsum 文本持续很长时间,我希望整个屏幕都可以滚动,但事实并非如此。
提前致谢!
【问题讨论】:
-
只是为了澄清,您是否尝试过任何其他布局?像scrollV中的线性或相对??
-
@SantanuSur 是的,我都试过了。结果相同。但谢谢你的想法。我还用图片更新了问题以澄清我的问题。
-
但是你在viewpager顶部的空白处做什么..你可以利用它..
-
应该有一张图片。
-
做一件事..用nestedScrollView替换scrollView..并在它周围放置一个线性布局..我正在写解决方案..
标签: android android-viewpager android-constraintlayout android-nestedscrollview