0

I have an activity which contain two Fragment, now I want them invisible when the Activity is created, I will show the Fragment according to the user input.

So I tried to set the Fragment invisbile in the layout file:

<fragment
    android:name="com.app.ui.ArticleListFragment"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/poiSearchFrag"
    android:visibility="gone"></fragment>

<fragment
    android:name="com.app.ui.ArticleReaderFragment"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:id="@+id/routeSearchFrag"
    android:visibility="gone"></fragment>

But it seems that this does not work.

How to fix it?

4

1 回答 1

0

您可以尝试将片段放在不同的布局中,然后使用 layout.setVisibility 属性根据用户输入更改可见性。所以布局将是:

Layout1
  |
  Fragment 1
Layout2
  |
  Fragment 2
于 2013-10-22T09:19:05.907 回答