Tuesday, March 15, 2011

different types of Views in Android

Views and ViewGroups

An Activity contains Views and ViewGroups. A View is a widget that has an appearance on screen. Examples of widgets are buttons, labels, text boxes, etc. A View derives from the base class android.view.View.

One or more Views can be grouped together into a ViewGroup. A ViewGroup (which is by itself is a special type of View) provides the layout in which you can order the appearance and sequence of views. Examples of Viewgroups are LinearLayout, FrameLayout, etc. A ViewGroup derives from the base class android.view.ViewGroup.

Android supports the following ViewGroups:

* LinearLayout
* AbsoluteLayout
* TableLayout
* RelativeLayout
* FrameLayout
* ScrollView


SurfaceView and View:

- Views are drawn in UI thread and surfaceView are drawn in a seperate thread. So if rendering takes long time, its better to use SurfaceView. Then for animations also, its better to use surfaceView.

- SurfaceView uses more resoources than View, so use it when you really want.

The data-view model

This is the model used by the library Swing of Java notably. The view is the interface through which the user interacts with the software. Data are stored separately and can be displayed in different views.
The view may also change the data according to the context, for example, change the text according to the user's language.

The Android model

Android extends this views/data model, it provides a new model that is suitable for equipment activated at all times. The structure of applications is defined as follows:

1. The views (Class android.view.View)

The interface of a program for Android is a tree of views.
The image at right shows four views inside a screen (an activity).

2. The file AndroidManifest.xml

It defines the components of the application and their relationships. It gives the permissions to application as to what it can do with users. It can also give permission to components of the application.

3. The components of the application:

* Activity (android.app.Activity class).
This is something that the user can do, translated into program. It corresponds to a screen, but can have multiple views.
* Intent (android.content.Intent class).
Describes an action which must be performed.
* Service (android.app.Service ).
Program that operates in background.
* Content Provider (android.content.ContentProvider class).
It encapsulates data and provides them commonly to several programs.
* Notification (android.app.NotificationManager and android.app.Notification classes).
Class which informs the user about what is happening.

Besides components, there are also resources that can be XML files, image files as jpeg. They use the android.content.Resources interface and are stored in the res directory.

No comments:

Post a Comment