2011-09-22 45 views
3

我一直在试图隐藏/显示片段并添加另一个片段。 这是XML如何隐藏/显示在xml中定义的片段

<FrameLayout 
     android:id="@+id/frag_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

      <fragment 
     class="com.tugce.MitsActionBar.KartvizitFragment" 
     android:id="@+id/frag_kartvizit" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     /> 
     </FrameLayout> 

调用其他的东西,再调用这个片段后,其mAdded属性为false,所以当我试图进入getView()为null。

我试过在这篇文章中的每一个编辑:Android Honeycomb: How to change Fragments in a FrameLayout, without re-creating them? 但仍然无法设法使其工作。

+0

看起来好像片段被添加到视图但看不到,并且它不被隐藏 – tugce

回答

1

您可以将android:visibility标志添加到xml内部的父级布局(在本例中为framelayout),并在您的java代码中使用该标志。