ViewPager in ScrollView(ScrollView 中的 ViewPager)
问题描述
我需要在 ScrollView 中有一个 ViewPager 但 ViewPager 在 ScrollView 中时不会出现,当我不使用 ScrollView 时一切正常.
I need to have a ViewPager inside a ScrollView but ViewPager just does not appear when it's in ScrollView, everything is ok when i don't use ScrollView.
我在 stackoverflow 或其他网站上看到了一些这样的问题,并且所有这些问题都已得到回答,您必须将 android:fillViewport="true" 放入您的滚动视图解决这个问题,但是这个解决方案对我不起作用,即使我的 ScrollView<中有 android:fillViewport="true" 仍然没有出现 ViewPager/代码>.
I've seen a couple questions like this being asked here on stackoverflow or on other sites and all of them have been answered that you have to put android:fillViewport="true" to your scrollview to fix the problem, but this solution doesnt work for me, ViewPager still does not appear even if i have android:fillViewport="true" in my ScrollView.
我猜想在 android api 中发生了一些变化,这个解决方案不再起作用了,有谁知道我怎么可能让 ViewPager 出现在 ScrollView?
I guess something got changed in the android api's or something and this solution doesn't work anymore, does anyone know how i could possibly make a ViewPager appear in a ScrollView?
更新:一个工作的 ScrollView 布局 XML:
UPDATE: A working ScrollView layout XML:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/itemsViewPager2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
</LinearLayout>
</ScrollView>
推荐答案
我过去也遇到过类似的问题.View-Pager 必须有一个设定的高度(它不能包装内容).由于 ViewPager 加载单独的页面,而不是一次加载,它不会知道包装内容"的实际含义.将 layout_height 设置为 fill_parent 或设置 dp 允许 ViewPager 静态设置它的高度并在其他布局中做出相应的反应.
I ran into a similar problem in the past. A View-Pager must have a set height (it cannot wrap-content). Since a ViewPager loads separate pages, and not all at once, it won't know what 'wrap-content' actually means. Setting the layout_height to fill_parent or a set dp allows the ViewPager to statically set it's height and react more accordingly within other layouts.
这篇关于ScrollView 中的 ViewPager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ScrollView 中的 ViewPager
基础教程推荐
- 固定小数的Android Money Input 2022-01-01
- 使用 Ryzen 处理器同时运行 WSL2 和 Android Studio 2022-01-01
- “让"到底是怎么回事?关键字在 Swift 中的作用? 2022-01-01
- Android文本颜色不会改变颜色 2022-01-01
- :hover 状态不会在 iOS 上结束 2022-01-01
- 在 iOS 上默认是 char 签名还是 unsigned? 2022-01-01
- LocationClient 与 LocationManager 2022-01-01
- 如何使用 YouTube API V3? 2022-01-01
- Android ViewPager:在 ViewPager 中更新屏幕外但缓存的片段 2022-01-01
- 如何使 UINavigationBar 背景透明? 2022-01-01
