blob: 206d96072f70c395cd0e36452d1e4d2ad14d238e [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>TODO(b/166518424) class signature</p>
<p>TODO(b/166518951) inheritance hierarchy</p>
<p>TODO(b/166518636) direct subclasses</p>
<p>TODO(b/166518636) indirect subclasses</p>
<hr>
<p>
<p>FragmentContainerView is a customized Layout designed specifically for Fragments. It extends , 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>&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)">onInflate</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)">findFragmentByTag</a></code> to retrieve the added Fragment. </p>
<pre>&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)">onCreateView</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)">setCustomAnimations</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>
</p>
<h2>Summary</h2>
<p>Nested *</p>
<p>Enum values</p>
<p>Constants</p>
<p>Public fields</p>
<p>Protected fields</p>
<p>Public constructors</p>
<p>Protected constructors</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<thead>
<tr>
<th colspan="2"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody>
<tr>
<td><code>&nbsp;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)">onCreateView</a></code> .</p>
</td>
</tr>
<tr>
<td><code>&nbsp;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>&nbsp;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>
<p>{@inheritDoc} </p>
<p>The sys ui flags must be set to enable extending the layout into the window insets.</p>
</p>
</td>
</tr>
<tr>
<td><code>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>&nbsp;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>
<p>When called, this method throws a <code><a href="/reference/java/lang/UnsupportedOperationException.html">UnsupportedOperationException</a></code> on APIs above 17.</p>
</p>
</td>
</tr>
<tr>
<td><code>&nbsp;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 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">&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)">onCreateView</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">&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">&nbsp;WindowInsets&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#onApplyWindowInsets(android.view.WindowInsets)">onApplyWindowInsets</a>(WindowInsets&nbsp;insets)</pre>
<p>
<p>{@inheritDoc} </p>
<p>The sys ui flags must be set to enable extending the layout into the window insets.</p>
</p>
</div>
<div><a name="removeAllViewsInLayout--"></a>
<h3 class="api-name" id="removeAllViewsInLayout()">removeAllViewsInLayout</h3>
<pre class="api-signature no-pretty-print">&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">&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">&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">&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">&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">&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">&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#setLayoutTransition(android.animation.LayoutTransition)">setLayoutTransition</a>(LayoutTransition&nbsp;transition)</pre>
<p>
<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 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)">setCustomAnimations</a></code> and <code><a href="/reference/androidx/fragment/app/FragmentTransaction.html#setTransition(int)">setTransition</a></code> .</p>
</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">&nbsp;void&nbsp;<a href="/reference/androidx/fragment/app/FragmentContainerView.html#startViewTransition(android.view.View)">startViewTransition</a>(View&nbsp;view)</pre>
</div>
</body>
</html>