-
<ViewGroup>
-
A container for other
ViewElements. There are unsupported different kinds
ViewGroupObjects and each one lets you specify the layout of the child elements in different ways. Different kinds
ViewGroupObjects include
LinearLayout,
RelativeLayout, And
FrameLayout.
You shoshould not assume that any derivationViewGroupWill accept nestedViewS. SomeViewGroupS are implementations ofAdapterViewClass, which determines its children only fromAdapter.
Attributes:
-
android:id
-
Resource ID. A unique resource name for the element, which you canuse to obtain a reference to
ViewGroupFrom your application. See moreabout the value
android:idBelow.
-
android:layout_height
-
Dimension or keyword.
Required. The height for the group, as adimension value (or dimension resource) or a keyword (
"fill_parent"Or
"wrap_content"). See the valid values below.
-
android:layout_width
-
Dimension or keyword.
Required. The width for the group, as adimension value (or dimension resource) or a keyword (
"fill_parent"Or
"wrap_content"). See the valid values below.
More attributes are supported byViewGroupBase class, and more are supported by each implementationViewGroup. For a reference of all available attributes, see the corresponding reference documentation forViewGroupClass (for example, the LinearLayout XMLattributes ).
-
<View>
-
An individual UI component, generally referred to as a "widget". Different kinds
ViewObjects include
TextView,
Button, And
CheckBox.
Attributes:
-
android:id
-
Resource ID. A unique resource name for the element, which you can use to obtain a reference to
ViewFrom your application. See more aboutthe value
android:idBelow.
-
android:layout_height
-
Dimension or keyword.
Required. The height for the element, asa dimension value (or dimension resource) or a keyword (
"fill_parent"Or
"wrap_content"). See the valid values below.
-
android:layout_width
-
Dimension or keyword.
Required. The width for the element, asa dimension value (or dimension resource) or a keyword (
"fill_parent"Or
"wrap_content"). See the valid values below.
More attributes are supported byViewBase class, and more are supported by each implementationView. Read Layouts for more information. Fora reference of all available attributes, see the corresponding reference documentation (for example, the TextView XML attributes ).
-
<requestFocus>
-
Any element representing
ViewObject can include this empty element, which gives its parent initial focus on the screen. You can have only one of these elements per file.
-
<include>
-
Except des a layout file into this layout.
Attributes:
-
layout
-
Layout resource.
Required. Reference to a layoutresource.
-
android:id
-
Resource ID. Overrides the ID given to the root view in the specified ded layout.
-
android:layout_height
-
Dimension or keyword. Overrides the height given to the root view in theincluded layout. Only valid tive if
android:layout_widthIs also declared.
-
android:layout_width
-
Dimension or keyword. Overrides the width given to the root view in theincluded layout. Only valid tive if
android:layout_heightIs also declared.
You can include any other layout attributes in<include>That aresupported by the root element in the included layout and they will override those defined in theroot element.
Caution:If you want to override layout attributes using<include>Tag, you must override bothandroid:layout_heightAndandroid:layout_widthIn order for other layout attributes to take effect.
Another way to include a layout is to useViewStub. It is a lightweightView that consumes no layout space until you explicitly inflate it, at which point, it should des alayout file defined by itsandroid:layoutAttribute. For more information about usingViewStub, Read Loading Views On Demand.
-
<merge>
-
An alternative root element that is not drawn in the layout hierarchy. using this as theroot element is useful when you know that this layout will be placed into a layoutthat already contains the appropriate parent View to contain the children of
<merge>Element. This is Special useful when you plan to include this layoutin another layout file using
<include>Andthis layout doesn' t require a different
ViewGroupContainer. For moreinformation about merging layouts, read Re-using Layouts with <include/>.
Value
android:id
For the ID value, you shoshould usually use this syntax form:"@+id/name". Theplus symbol,+, Indicates that this is a new resource ID andaaptTool willcreate a new resource integer inR.javaClass, if it doesn' t already exist. Forexample:
<TextView android:id="@+id/nameTextbox"/>
ThenameTextboxName is now a resource ID attached to this element. You can thenrefer toTextViewTo which the ID is associated in Java:
findViewById(R.id.nameTextbox);
This code returnsTextViewObject.
However, if you have already defined an ID resource (and it is notalready used), then you can apply that ID toViewElement by excluding theplus symbol inandroid:idValue.
Value
android:layout_heightAnd
android:layout_width:
The height and width value can be expressed using any of the dimension units supported by Android (px, dp, sp, pt, in, mm) or with the following keywords:
| Value |
Description |
match_parent |
Sets the dimension to match that of the parent element. Added in API Level 8 todeprecatefill_parent. |
fill_parent |
Sets the dimension to match that of the parent element. |
wrap_content |
Sets the dimension only to the size required to fit the content of this element. |
Custom View elements
You can create your own mViewAndViewGroupElements and apply them to your layout the same as a standard layoutelement. You can also specify the attributes supported in the XML element. To learn more, see the Custom Components release guide.