Beruflich Dokumente
Kultur Dokumente
All user interface elements in an Android app are built using View and ViewGroup objects.
A View is an object that draws something on the screen that the user can interact with.
Android provides a collection of both View and ViewGroup subclasses that offer you
common input controls (such as buttons and text fields) and various layout models (such as a
linear or relative layout).
To declare your layout, you can instantiate View objects in code and start building a tree, but
the easiest and most effective way to define your layout is with an XML file. XML offers a
human-readable structure for the layout, similar to HTML.
The name of an XML element for a view is respective to the Android class it
represents.
So a <TextView> XML element creates a TextView class widget in your UI, and
a <LinearLayout> XML element creates a LinearLayout view group.
For example, a simple vertical layout with a text view and a button looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a TextView" />
<Button android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I am a Button" />
</LinearLayout>
***When you load a layout resource in your app, Android initializes each node of the
layout into a runtime object you can use to define additional behaviors, query the object state,
or modify the layout.
View (android.view.View):
1. This class represents the basic building block for user interface components.
2. A View occupies a rectangular area on the screen and is responsible for drawing and
event handling.
3. View is the base class for widgets, which are used to create interactive UI components
(buttons, text fields, etc.).
4. The ViewGroup subclass of View is the base class for layouts, which are invisible
containers that hold other Views (or other ViewGroups) and define their layout
properties.
5. All of the views in a window are arranged in a single tree. You can add views either from
code or by specifying a tree of views in one or more XML layout file.