My activity declares all of its GUI fragments in a single XML layout. It only needs to display a few of the fragments at launch time; the rest get shown as the user interacts with the app. A portion of the layout is as follows:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map_panel"
android:name="com.example.MapPanel"
android:layout_width="match_parent"
android:layout_height="@dimen/map_panel_height" />
<fragment
android:id="@+id/list_panel"
android:name="com.example.ListPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/map_panel" />
<fragment
android:id="@+id/detail_panel"
android:name="com.example.DetailPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/map_panel"
android:visibility="gone" />
My intention is that the list_panel
fragment is visible at startup, and the detail_panel
fragment is hidden until the user selects something from the list.
By default, a fragment starts out with the isHidden
attribute as false. That means my activity has to iterate through the loaded fragments and manually call isHidden(true)
on fragments like detail_panel
at startup time.
I would prefer to declare the isHidden
status in the XML layout. However, setting android:visibility="gone"
in a <fragment>
declaration does not change the isHidden
status, and I can't find any documentation on another attribute that would do the trick.
Is it possible to set an XML attribute on a <fragment>
to cause it to be hidden?
Note: I'm not concerned with view visibility, I'm concerned with the fragment.isHidden()
value. That affects how FragmentManager manipulates the back stack and performs animations. If you call transaction.show(fragment)
on a fragment whose view is invisible or gone, but the fragment.isHidden()
value is false, then the FragmentManager will not make the view visible. See http://developer.android.com/reference/android/app/Fragment.html#isHidden() for reference.