Android Views and ViewGroups

3 August 2023
1
Share

Android Views and ViewGroups are crucial parts of building engaging Android apps. New developers should understand their differences and how they work together to create captivating user interfaces.

Android Views

Views are the basic building blocks for the elements of the User Interface.

A view is the UI element such as button, label, text field etc. Anything that you see is a view.

A View fills a rectangular area on the screen and is responsible for drawing and event handling.

All Views inherit from View class (android.view.View)

Listed as follows are some of the common View subclasses which will be used in Android applications:

  • TextView
  • EditText
  • Button
  • CheckBox
  • RadioButton
  • ImageButton
  • Progress Bar
  • Spinner

Android ViewGroups

The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties.

  • The ViewGroup is a subclass of View.

The following are the commonly used ViewGroup subclasses in Android applications:

Linear Layout

This layout is ViewGroup that align all children in single direction,vertically or horizontally.

Relative Layout

This layout is ViewGroup that display child view in relative position.

Table Layout

This layout is view that groups views into rows and columns.

Frame Layout

This is the placeholder on screen that you can use to display a sigle view.

Absolute Layout

This layout enables you to specify the exact location of its children.

Web View

This View display web pages inside application.

List View

This view displays a list of scrollable items.

Grid View

This is ViewGroup that display items in a two dimensional,scrollable grid.

ListView and GridView are subclass of AdapterView and they can be populated by binding them to an adapter,which receives data from an external source and creates View that represents each data entry.

Android view and view groups.

Important Notes

  • The component view shows certain warnings sometimes. Correcting these by following good practices is recommended.
  • You can resize the preview as per the device of your liking in the Design view itself.
  • Android Studio uses Gradle as the build system.
  • You don’t have to remember all the attributes of every View

Build a UI with Views

The Layout Editor enables you to quickly build layouts by dragging UI elements into a visual design editor instead of writing layout XML by hand. The design editor can preview your layout on different Android devices and versions, and you can dynamically resize the layout to be sure it works well on different screen sizes.

  1. Palette: Contains various views and view groups that you can drag into your layout.
  2. Component Tree: Shows the hierarchy of components in your layout.
  3. Toolbar: Click these buttons to configure your layout appearance in the editor and change layout attributes.
  4. Design editor: Edit your layout in Design view, Blueprint view, or both.
  5. Attributes: Controls for the selected view’s attributes.
  6. View mode: View your layout in either Code  , Design  , or Split  Split mode shows both the Code and Design windows at the same time.
  7. Zoom and pan controls: Control the preview size and position within the editor

The Layout Editor appears when you open an XML layout file.

For more visit:Develop a UI with Views

Next:What The Weird Word! Android app