【问题标题】:how to hide/show fragment defined in xml如何隐藏/显示在 xml 中定义的片段
【发布时间】:2011-09-22 11:49:50
【问题描述】:

我一直在尝试隐藏/显示片段并添加另一个片段。 这是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() 时,它为空。

我尝试了这篇文章中的所有编辑:Android Honeycomb: How to change Fragments in a FrameLayout, without re-creating them? 但仍然无法使其工作。

【问题讨论】:

  • 好像fragment被添加到视图中但没有看到,并且没有隐藏

标签: android android-layout


【解决方案1】:

您可以将android:visibility 标志添加到xml 中片段的父布局(在本例中为framelayout),并在您的Java 代码中使用它。

【讨论】:

    猜你喜欢
    • 2014-09-06
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多