【问题标题】:How can I show a ViewPager in fullscreen mode?如何在全屏模式下显示 ViewPager?
【发布时间】:2013-09-09 22:37:45
【问题描述】:
通过在其中包含 ViewPager 的 Activity,是否可以在单击时将 ViewPager 设置为全屏(开/假)?
如果没有,我将在全屏模式下启动一个新活动,其中包含同一个 ViewPager 的另一个实例,并手动对两个 ViewPager CurrentItem 进行 sincronize,这将需要更多内存和更多要实例化的对象。
实现此功能的最佳方法是什么?
【问题讨论】:
标签:
android
android-fragments
android-viewpager
fullscreen
tap
【解决方案1】:
David Neto 的建议很好。
但是:您不需要将所有其他视图的布局宽度和高度设置为0。
你需要做什么:
- 将所有其他视图的可见性设置为
View.GONE,这样更容易
如果您的 ViewPager 具有宽度和高度的“match_parent”属性,那么就是这样。如果没有,请将它们设置为“match_parent”。
【解决方案2】:
也许您可以在 ViewPager 上设置一个 onClickListener 来执行以下操作:
if flag == 0 {
set the other Views surrounding the ViewPager layout_width and layout_height to 0dp;
set the ViewPager layout_width and layout_height to 0dp AND layout_weight to 1;
flag = 1;
}
elseif(flag == 1) {
set other Views layout_width and layout_height to their normal values;
set the ViewPager layout_width and layout_height to their normal values also;
flag = 0;
}
也许这会有所帮助,不确定这是否是最正确的方法,但我认为它会起作用。另外,这是伪代码,只是为了解释这个想法,它不是正确的 Java 代码(显然):)