>屏幕上有两个垂直放置的元素(VIEwPager和Fragment)
>第一个当前选定片段(VIEwFlipper)中的 *** 作在顶部片段中基于文本和基于WebVIEw的视图之间切换,并隐藏/显示底部片段.
观测到的:
>隐藏底部片段会留下底部片段所在的空白区域.
我尝试了relative和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();
以下是它的外观:
解决方法 一个月后,我想出了如何做到这一点.事实证明,仅仅隐藏片段是不够的,基本上我需要隐藏/显示包含片段的shell.它仍然是最初在XML中定义的linearLayout.实际上,在原始布局上设置可见性以显示/隐藏片段就足够了.所以问题中的代码现在看起来像这样:public voID onJobVIEwToggled(final boolean isWebVIEw) { if (isFinishing()) return; final Fragment scroll = getSupportFragmentManager().findFragmentByID(R.ID.scrollFragment); if (scroll.isHIDden() == isWebVIEw) return; // already handled,do nothing final FragmentTransaction tr = getSupportFragmentManager().beginTransaction(); if (scroll != null && scroll.isAdded()) { if (isWebVIEw) { tr.hIDe(scroll); // shell is the original placeholder shell.setVisibility(VIEw.GONE); } else { tr.show(scroll); shell.setVisibility(VIEw.VISIBLE); } } tr.commit();}
请注意,您仍然希望显示/隐藏片段以使其工作
总结以上是内存溢出为你收集整理的Android – 显示/隐藏片段留下空白区域全部内容,希望文章能够帮你解决Android – 显示/隐藏片段留下空白区域所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)