Skip to content

Commit 93116f8

Browse files
scottamainAndroid Git Automerger
authored andcommitted
am 3577f51: docs: clarify <include> layout properties bug: 3227820
* commit '3577f51d4bc236a11e283855337752a7b6897f8b': docs: clarify <include> layout properties bug: 3227820
2 parents 5df8c15 + 3577f51 commit 93116f8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

docs/html/guide/topics/resources/layout-resource.jd

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,23 @@ resource.</dd>
149149
</dd>
150150
<dt><code>android:layout_height</code></dt>
151151
<dd><em>Dimension or keyword</em>. Overrides the height given to the root view in the
152-
included layout.
152+
included layout. Only effective if <code>android:layout_width</code> is also declared.
153153
</dd>
154154
<dt><code>android:layout_width</code></dt>
155155
<dd><em>Dimension or keyword</em>. Overrides the width given to the root view in the
156-
included layout.
156+
included layout. Only effective if <code>android:layout_height</code> is also declared.
157157
</dd>
158158
</dl>
159159
<p>You can include any other layout attributes in the <code>&lt;include&gt;</code> that are
160160
supported by the root element in the included layout and they will override those defined in the
161161
root element.</p>
162162

163+
<p class="caution"><strong>Caution:</strong> If you want to override the layout dimensions,
164+
you must override both <code>android:layout_height</code> and
165+
<code>android:layout_width</code>&mdash;you cannot override only the height or only the width.
166+
If you override only one, it will not take effect. (Other layout properties, such as weight,
167+
are still inherited from the source layout.)</p>
168+
163169
<p>Another way to include a layout is to use {@link android.view.ViewStub}. It is a lightweight
164170
View that consumes no layout space until you explicitly inflate it, at which point, it includes a
165171
layout file defined by its {@code android:layout} attribute. For more information about using {@link

docs/html/resources/articles/layout-tricks-reuse.jd

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,24 @@ attributes of the included layout. The above example shows that you can use
5353
layout; it will also override the id of the included layout if one is defined.
5454
Similarly, you can override all the layout parameters. This means that any
5555
<code>android:layout_*</code> attribute can be used with the <code>&lt;include
56-
/&gt;</code> tag. Here is an example:</p>
56+
/&gt;</code> tag. Here is an example in
57+
which the same layout is included twice, but only the first one overrides the layout properties:</p>
5758

58-
<pre class="prettyprint">&lt;include android:layout_width="fill_parent" layout="@layout/image_holder" /&gt;
59-
&lt;include android:layout_width="256dip" layout="@layout/image_holder" /&gt;
59+
<pre>
60+
&lt;!-- override the layout height and width --&gt;
61+
&lt;include layout="@layout/image_holder"
62+
android:layout_height="fill_parent"
63+
android:layout_width="fill_parent" /&gt;
64+
&lt;!-- do not override layout dimensions; inherit them from image_holder --&gt;
65+
&lt;include layout="@layout/image_holder" /&gt;
6066
</pre>
6167

68+
<p class="caution"><strong>Caution:</strong> If you want to override the layout dimensions,
69+
you must override both <code>android:layout_height</code> and
70+
<code>android:layout_width</code>&mdash;you cannot override only the height or only the width.
71+
If you override only one, it will not take effect. (Other layout properties, such as weight,
72+
are still inherited from the source layout.)</p>
73+
6274
<p>This tag is particularly useful when you need to customize only part of your
6375
UI depending on the device's configuration. For instance, the main layout of
6476
your activity can be placed in the <code>layout/</code> directory and can

0 commit comments

Comments
 (0)