blob: 39f67099a7b328f61be4a70b5402f053fedbe014 [file] [log] [blame]
<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">&lt;androidx.fragment.app.FragmentContainerView
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:id=&quot;@+id/fragment_container_view&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;&gt;
&lt;/androidx.fragment.app.FragmentContainerView&gt;
</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">&lt;androidx.fragment.app.FragmentContainerView
xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
android:id=&quot;@+id/fragment_container_view&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:name=&quot;com.example.MyFragment&quot;
android:tag=&quot;my_tag&quot;&gt;
&lt;/androidx.fragment.app.FragmentContainerView&gt;
</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&nbsp;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&nbsp;context,&nbsp;AttributeSet&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;Context&nbsp;context,<br>&nbsp;&nbsp;&nbsp;&nbsp;AttributeSet&nbsp;attrs,<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;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&nbsp;child,&nbsp;int&nbsp;index,&nbsp;LayoutParams&nbsp;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&nbsp;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&nbsp;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&nbsp;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&nbsp;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&nbsp;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&nbsp;start,&nbsp;int&nbsp;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&nbsp;start,&nbsp;int&nbsp;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&nbsp;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&nbsp;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&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context)">FragmentContainerView</a>(Context&nbsp;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&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet)">FragmentContainerView</a>(Context&nbsp;context,&nbsp;AttributeSet&nbsp;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&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#FragmentContainerView(android.content.Context,android.util.AttributeSet,int)">FragmentContainerView</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;Context&nbsp;context,<br>&nbsp;&nbsp;&nbsp;&nbsp;AttributeSet&nbsp;attrs,<br>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#addView(android.view.View,int,android.view.ViewGroup.LayoutParams)">addView</a>(View&nbsp;child,&nbsp;int&nbsp;index,&nbsp;LayoutParams&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#endViewTransition(android.view.View)">endViewTransition</a>(View&nbsp;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&nbsp;WindowInsets&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#onApplyWindowInsets(android.view.WindowInsets)">onApplyWindowInsets</a>(WindowInsets&nbsp;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&nbsp;void&nbsp;<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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeView(android.view.View)">removeView</a>(View&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewAt(int)">removeViewAt</a>(int&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewInLayout(android.view.View)">removeViewInLayout</a>(View&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViews(int,int)">removeViews</a>(int&nbsp;start,&nbsp;int&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#removeViewsInLayout(int,int)">removeViewsInLayout</a>(int&nbsp;start,&nbsp;int&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</a>(LayoutTransition&nbsp;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&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#startViewTransition(android.view.View)">startViewTransition</a>(View&nbsp;view)</pre>
</div>
</body>
</html>