【发布时间】:2017-09-10 06:46:58
【问题描述】:
我有一个 ViewPager,它位于父线性布局内,在 ViewPager 下方有一些按钮。 ViewPager 一直运行良好,直到最近我将父级从 LinearLayout 更改为 ScrollView。现在 ViewPager 消失了。请不要将其标记为垃圾邮件或重复。
此外,Playstore 上有大量应用目前正在使用此功能。看到这个应用程序 - link
我尝试了什么:
- setFillViewport (true) - 这对我不起作用。
- 将 layout_height 设置为 0dp
- 使用 CustomScrollView
所有这些都对我没有帮助。我在 Android M 上运行该应用程序。
这是我的 layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".activities.HomeActivity">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:onClick="pagerClick"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="top"
android:layout_weight="1"
android:overScrollMode="never"/>
<RelativeLayout
android:layout_weight="0.8"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
.....two buttons
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
问题:
我怎样才能做到这一点?另外,有官方的方法吗?
【问题讨论】:
-
将你的嵌套滚动视图放在父布局中,例如:coordinatorLayout
-
这也无济于事
-
发布完整的 xml..
-
添加了完整的 layout.xml
标签: android android-layout android-viewpager scrollview