【发布时间】:2012-05-28 07:26:32
【问题描述】:
给定:
- 屏幕上的两个垂直放置的元素(ViewPager 和 Fragment)
- 当前选中的第一个片段 (ViewFlipper) 中的操作在顶部片段中基于文本和基于 WebView 的视图之间切换,并隐藏/显示底部片段。
观察到:
- 隐藏底部片段会留下底部片段所在的空白空间。
我尝试了 RelativeLayout 和 LinearLayout(顶部片段设置为 weight=1),但在底部片段被移除后两者都没有效果我底部仍有空白空间
这是顶层布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"/>
<!-- This gets replaced with appropriate fragment at run time -->
<LinearLayout
android:id="@+id/scrollFragmentPlaceholder"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="110dip" />
</LinearLayout>
这里是切换片段的代码
Fragment scroll = getSupportFragmentManager().findFragmentById(R.id.scrollFragment);
if (scroll.isHidden() == isWebView)
return; // already handled, do nothing
FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
if (scroll != null && scroll.isAdded()) {
if (isWebView) {
tr.hide(scroll);
} else
tr.show(scroll);
}
tr.commit();
它的外观如下:
【问题讨论】:
-
你有没有试过在剩下的视图上做 *.measure() ?
-
不是真的,但是如果我颠倒顺序并显示文本版本/隐藏底部它会正确显示
-
Android 的 WebView 太奇怪了。您能否附上一些屏幕截图,以便我可以更具体地看到您在说什么?如果您希望它们占用一半的可用空间,您还需要在两个视图上设置 layoutWeight = 1。您还需要确保在父视图中指定orientation="vertical"。
-
不 - 这不是 WebView,抱歉。文本也会留下一个空白空间。我会在问题中添加一些代码
-
你是躲在
View.GONE还是View.INVISIBLE?
标签: android webview show-hide fragment