Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3577f51d authored by Scott Main's avatar Scott Main
Browse files

docs: clarify <include> layout properties

bug: 3227820

Change-Id: Id5130cd805ee2ea545a795019fb375ffd841727f
parent 2cbe92ea
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -149,17 +149,23 @@ resource.</dd>
        </dd>
        <dt><code>android:layout_height</code></dt>
        <dd><em>Dimension or keyword</em>. Overrides the height given to the root view in the
included layout.
included layout. Only effective if <code>android:layout_width</code> is also declared.
        </dd>
        <dt><code>android:layout_width</code></dt>
        <dd><em>Dimension or keyword</em>. Overrides the width given to the root view in the
included layout.
included layout. Only effective if <code>android:layout_height</code> is also declared.
        </dd>
      </dl>
      <p>You can include any other layout attributes in the <code>&lt;include&gt;</code> that are
supported by the root element in the included layout and they will override those defined in the
root element.</p>

      <p class="caution"><strong>Caution:</strong> If you want to override the layout dimensions,
you must override both <code>android:layout_height</code> and
<code>android:layout_width</code>&mdash;you cannot override only the height or only the width.
If you override only one, it will not take effect. (Other layout properties, such as weight,
are still inherited from the source layout.)</p>

    <p>Another way to include a layout is to use {@link android.view.ViewStub}. It is a lightweight
View that consumes no layout space until you explicitly inflate it, at which point, it includes a
layout file defined by its {@code android:layout} attribute. For more information about using {@link
+15 −3
Original line number Diff line number Diff line
@@ -53,12 +53,24 @@ attributes of the included layout. The above example shows that you can use
layout; it will also override the id of the included layout if one is defined.
Similarly, you can override all the layout parameters. This means that any
<code>android:layout_*</code> attribute can be used with the <code>&lt;include
/&gt;</code> tag. Here is an example:</p>
/&gt;</code> tag. Here is an example in
which the same layout is included twice, but only the first one overrides the layout properties:</p>

<pre class="prettyprint">&lt;include android:layout_width="fill_parent" layout="@layout/image_holder" /&gt;
&lt;include android:layout_width="256dip" layout="@layout/image_holder" /&gt;
<pre>
&lt;!-- override the layout height and width --&gt;
&lt;include layout="@layout/image_holder"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" /&gt;
&lt;!-- do not override layout dimensions; inherit them from image_holder --&gt;
&lt;include layout="@layout/image_holder" /&gt;
</pre>

<p class="caution"><strong>Caution:</strong> If you want to override the layout dimensions,
you must override both <code>android:layout_height</code> and
<code>android:layout_width</code>&mdash;you cannot override only the height or only the width.
If you override only one, it will not take effect. (Other layout properties, such as weight,
are still inherited from the source layout.)</p>

<p>This tag is particularly useful when you need to customize only part of your
UI depending on the device's configuration. For instance, the main layout of
your activity can be placed in the <code>layout/</code> directory and can