-
<ViewGroup>
-
A container for other
View
Elements. There are unsupported different kinds
ViewGroup
Objects and each one lets you specify the layout of the child elements in different ways. Different kinds
ViewGroup
Objects include
LinearLayout
,
RelativeLayout
, And
FrameLayout
.
You shoshould not assume that any derivationViewGroup
Will accept nestedView
S. SomeViewGroup
S are implementations ofAdapterView
Class, 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
ViewGroup
From your application. See moreabout the value
android:id
Below.
-
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 byViewGroup
Base class, and more are supported by each implementationViewGroup
. For a reference of all available attributes, see the corresponding reference documentation forViewGroup
Class (for example, the LinearLayout XMLattributes ).
-
<View>
-
An individual UI component, generally referred to as a "widget". Different kinds
View
Objects 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
View
From your application. See more aboutthe value
android:id
Below.
-
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 byView
Base 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
View
Object 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_width
Is 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_height
Is 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_height
Andandroid:layout_width
In 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:layout
Attribute. 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
ViewGroup
Container. 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 andaapt
Tool willcreate a new resource integer inR.java
Class, if it doesn' t already exist. Forexample:
<TextView android:id="@+id/nameTextbox"/>
ThenameTextbox
Name is now a resource ID attached to this element. You can thenrefer toTextView
To which the ID is associated in Java:
findViewById(R.id.nameTextbox);
This code returnsTextView
Object.
However, if you have already defined an ID resource (and it is notalready used), then you can apply that ID toView
Element by excluding theplus symbol inandroid:id
Value.
Value
android:layout_height
And
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 mView
AndViewGroup
Elements 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.