| <html devsite="true"> |
| <head> |
| <title>FragmentContainerView</title> |
| {% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} |
| {% include "_shared/_reference-head-tags.html" %} |
| </head> |
| <body> |
| <h1>FragmentContainerView</h1> |
| {% setvar page_path %}androidx/fragment/app/FragmentContainerView.html{% endsetvar %} |
| {% setvar can_switch %}1{% endsetvar %} |
| {% include "reference/_java_switcher2.md" %} |
| <p> |
| <pre>public final class FragmentContainerView</pre> |
| </p> |
| <hr> |
| <p>FragmentContainerView is a customized Layout designed specifically for Fragments. It extends FrameLayout, so it can reliably handle Fragment Transactions, and it also has additional features to coordinate with fragment behavior. </p> |
| <p>FragmentContainerView should be used as the container for Fragments, commonly set in the xml layout of an activity, e.g.: </p> |
| <pre class="prettyprint"><androidx.fragment.app.FragmentContainerView |
| xmlns:android="http://schemas.android.com/apk/res/android" |
| xmlns:app="http://schemas.android.com/apk/res-auto" |
| android:id="@+id/fragment_container_view" |
| android:layout_width="match_parent" |
| android:layout_height="match_parent"> |
| </androidx.fragment.app.FragmentContainerView> |
| </pre> |
| <p> FragmentContainerView can also be used to add a Fragment by using the <code>android:name</code> attribute. FragmentContainerView will perform a one time operation that: </p> |
| <ul> |
| <li>Creates a new instance of the Fragment</li> |
| <li>Calls <code><a href="/reference/androidx/fragment/app/Fragment.html#onInflate(android.content.Context,android.util.AttributeSet,android.os.Bundle)">Fragment#onInflate(Context, AttributeSet, Bundle)</a></code></li> |
| <li>Executes a FragmentTransaction to add the Fragment to the appropriate FragmentManager</li> |
| </ul> |
| <p> You can optionally include an <code>android:tag</code> which allows you to use <code><a href="/reference/androidx/fragment/app/FragmentManager.html#findFragmentByTag(java.lang.String)">FragmentManager#findFragmentByTag(String)</a></code> to retrieve the added Fragment. </p> |
| <pre class="prettyprint"><androidx.fragment.app.FragmentContainerView |
| xmlns:android="http://schemas.android.com/apk/res/android" |
| xmlns:app="http://schemas.android.com/apk/res-auto" |
| android:id="@+id/fragment_container_view" |
| android:layout_width="match_parent" |
| android:layout_height="match_parent" |
| android:name="com.example.MyFragment" |
| android:tag="my_tag"> |
| </androidx.fragment.app.FragmentContainerView> |
| </pre> |
| <p>FragmentContainerView should not be used as a replacement for other ViewGroups (FrameLayout, LinearLayout, etc) outside of Fragment use cases. </p> |
| <p>FragmentContainerView will only allow views returned by a Fragment's <code><a href="/reference/androidx/fragment/app/Fragment.html#onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)">Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)</a></code>. Attempting to add any other view will result in an <code><a href="/reference/java/lang/IllegalStateException.html">IllegalStateException</a></code>. </p> |
| <p>Layout animations and transitions are disabled for FragmentContainerView for APIs above 17. Otherwise, Animations should be done through <code><a href="/reference/androidx/fragment/app/FragmentTransaction.html#setCustomAnimations(int,int,int,int)">FragmentTransaction#setCustomAnimations(int, int, int, int)</a></code>. If animateLayoutChanges is set to <code>true</code> or <code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</a></code> is called directly an <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code> will be thrown. </p> |
| <p>Fragments using exit animations are drawn before all others for FragmentContainerView. This ensures that exiting Fragments do not appear on top of the view.</p> |
| <h2>Summary</h2> |
| <div class="devsite-table-wrapper"> |
| <table class="responsive"> |
| <thead> |
| <tr> |
| <th colspan="2"><h3>Public constructors</h3></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context)">FragmentContainerView</a>(Context context)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet)">FragmentContainerView</a>(Context context, AttributeSet attrs)</code></div> |
| <p>Do not call this constructor directly.</p> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet,int)">FragmentContainerView</a>(<br> Context context,<br> AttributeSet attrs,<br> int defStyleAttr<br>)</code></div> |
| <p>Do not call this constructor directly.</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <div class="devsite-table-wrapper"> |
| <table class="responsive"> |
| <thead> |
| <tr> |
| <th colspan="2"><h3>Public methods</h3></th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#addView(android.view.View,int,android.view.ViewGroup.LayoutParams)">addView</a>(View child, int index, LayoutParams params)</code></div> |
| <p>FragmentContainerView will only allow views returned by a Fragment's <code><a href="/reference/androidx/fragment/app/Fragment.html#onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)">Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)</a></code>.</p> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#endViewTransition(android.view.View)">endViewTransition</a>(View view)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>WindowInsets</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#onApplyWindowInsets(android.view.WindowInsets)">onApplyWindowInsets</a>(WindowInsets insets)</code></div> |
| <p>{@inheritDoc} </p> |
| <p>The sys ui flags must be set to enable extending the layout into the window insets.</p> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeAllViewsInLayout()">removeAllViewsInLayout</a>()</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeView(android.view.View)">removeView</a>(View view)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewAt(int)">removeViewAt</a>(int index)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewInLayout(android.view.View)">removeViewInLayout</a>(View view)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViews(int,int)">removeViews</a>(int start, int count)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewsInLayout(int,int)">removeViewsInLayout</a>(int start, int count)</code></div> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</a>(LayoutTransition transition)</code></div> |
| <p>When called, this method throws a <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code> on APIs above 17.</p> |
| </td> |
| </tr> |
| <tr> |
| <td><code>void</code></td> |
| <td width="100%"> |
| <div><code><a href="/reference/androidx/fragment/app/FragmentContainerView.html#startViewTransition(android.view.View)">startViewTransition</a>(View view)</code></div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| <h2>Public constructors</h2> |
| <div><a name="FragmentContainerView-android.content.Context-"></a> |
| <h3 class="api-name" id="FragmentContainerView(android.content.Context)">FragmentContainerView</h3> |
| <pre class="api-signature no-pretty-print">public <a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context)">FragmentContainerView</a>(Context context)</pre> |
| </div> |
| <div><a name="FragmentContainerView(android.content.Context, android.util.AttributeSet)"></a><a name="FragmentContainerView-android.content.Context-android.util.AttributeSet-"></a> |
| <h3 class="api-name" id="FragmentContainerView(android.content.Context,android.util.AttributeSet)">FragmentContainerView</h3> |
| <pre class="api-signature no-pretty-print">public <a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet)">FragmentContainerView</a>(Context context, AttributeSet attrs)</pre> |
| <p>Do not call this constructor directly. Doing so will result in an <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code>.</p> |
| </div> |
| <div><a name="FragmentContainerView(android.content.Context, android.util.AttributeSet, int)"></a><a name="FragmentContainerView-android.content.Context-android.util.AttributeSet-int-"></a> |
| <h3 class="api-name" id="FragmentContainerView(android.content.Context,android.util.AttributeSet,int)">FragmentContainerView</h3> |
| <pre class="api-signature no-pretty-print">public <a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet,int)">FragmentContainerView</a>(<br> Context context,<br> AttributeSet attrs,<br> int defStyleAttr<br>)</pre> |
| <p>Do not call this constructor directly. Doing so will result in an <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code>.</p> |
| </div> |
| <h2>Public methods</h2> |
| <div><a name="addView(android.view.View, int, android.view.ViewGroup.LayoutParams)"></a><a name="addView-android.view.View-int-android.view.ViewGroup.LayoutParams-"></a> |
| <h3 class="api-name" id="addView(android.view.View,int,android.view.ViewGroup.LayoutParams)">addView</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#addView(android.view.View,int,android.view.ViewGroup.LayoutParams)">addView</a>(View child, int index, LayoutParams params)</pre> |
| <p>FragmentContainerView will only allow views returned by a Fragment's <code><a href="/reference/androidx/fragment/app/Fragment.html#onCreateView(android.view.LayoutInflater,android.view.ViewGroup,android.os.Bundle)">Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)</a></code>. Attempting to add any other view will result in an <code><a href="/reference/java/lang/IllegalStateException.html">IllegalStateException</a></code>. {@inheritDoc}</p> |
| </div> |
| <div><a name="endViewTransition-android.view.View-"></a> |
| <h3 class="api-name" id="endViewTransition(android.view.View)">endViewTransition</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#endViewTransition(android.view.View)">endViewTransition</a>(View view)</pre> |
| </div> |
| <div><a name="onApplyWindowInsets-android.view.WindowInsets-"></a> |
| <h3 class="api-name" id="onApplyWindowInsets(android.view.WindowInsets)">onApplyWindowInsets</h3> |
| <pre class="api-signature no-pretty-print">public WindowInsets <a href="/reference/androidx/fragment/app/FragmentContainerView.html#onApplyWindowInsets(android.view.WindowInsets)">onApplyWindowInsets</a>(WindowInsets insets)</pre> |
| <p>{@inheritDoc} </p> |
| <p>The sys ui flags must be set to enable extending the layout into the window insets.</p> |
| </div> |
| <div><a name="removeAllViewsInLayout--"></a> |
| <h3 class="api-name" id="removeAllViewsInLayout()">removeAllViewsInLayout</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeAllViewsInLayout()">removeAllViewsInLayout</a>()</pre> |
| </div> |
| <div><a name="removeView-android.view.View-"></a> |
| <h3 class="api-name" id="removeView(android.view.View)">removeView</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeView(android.view.View)">removeView</a>(View view)</pre> |
| </div> |
| <div><a name="removeViewAt-int-"></a> |
| <h3 class="api-name" id="removeViewAt(int)">removeViewAt</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewAt(int)">removeViewAt</a>(int index)</pre> |
| </div> |
| <div><a name="removeViewInLayout-android.view.View-"></a> |
| <h3 class="api-name" id="removeViewInLayout(android.view.View)">removeViewInLayout</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewInLayout(android.view.View)">removeViewInLayout</a>(View view)</pre> |
| </div> |
| <div><a name="removeViews(int, int)"></a><a name="removeViews-int-int-"></a> |
| <h3 class="api-name" id="removeViews(int,int)">removeViews</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViews(int,int)">removeViews</a>(int start, int count)</pre> |
| </div> |
| <div><a name="removeViewsInLayout(int, int)"></a><a name="removeViewsInLayout-int-int-"></a> |
| <h3 class="api-name" id="removeViewsInLayout(int,int)">removeViewsInLayout</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewsInLayout(int,int)">removeViewsInLayout</a>(int start, int count)</pre> |
| </div> |
| <div><a name="setLayoutTransition-android.animation.LayoutTransition-"></a> |
| <h3 class="api-name" id="setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</a>(LayoutTransition transition)</pre> |
| <p>When called, this method throws a <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code> on APIs above 17. On APIs 17 and below, it calls FrameLayout#setLayoutTransition(LayoutTransition) This can be called either explicitly, or implicitly by setting animateLayoutChanges to <code>true</code>. </p> |
| <p>View animations and transitions are disabled for FragmentContainerView for APIs above 17. Use <code><a href="/reference/androidx/fragment/app/FragmentTransaction.html#setCustomAnimations(int,int,int,int)">FragmentTransaction#setCustomAnimations(int, int, int, int)</a></code> and <code><a href="/reference/androidx/fragment/app/FragmentTransaction.html#setTransition(int)">FragmentTransaction#setTransition(int)</a></code>.</p> |
| <div class="devsite-table-wrapper"> |
| <table class="responsive"> |
| <thead> |
| <tr> |
| <th colspan="2">Parameters</th> |
| </tr> |
| </thead> |
| <tbody> |
| <tr> |
| <td><code>transition</code></td> |
| <td width="100%"> |
| <p>The LayoutTransition object that will animated changes in layout. A value of <code>null</code> means no transition will run on layout changes.</p> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| </div> |
| <div><a name="startViewTransition-android.view.View-"></a> |
| <h3 class="api-name" id="startViewTransition(android.view.View)">startViewTransition</h3> |
| <pre class="api-signature no-pretty-print">public void <a href="/reference/androidx/fragment/app/FragmentContainerView.html#startViewTransition(android.view.View)">startViewTransition</a>(View view)</pre> |
| </div> |
| </body> |
| </html> |