Home > Articles > Mobile Application Development & Programming

Android Programming Unleashed: Laying Controls in Containers

  • Print
  • + Share This
  • 💬 Discuss
A container is a view used to contain other views. Android offers a collection of view classes that act as containers for views. These container classes are called layouts, and as the name suggests, they decide the organization, size, and position of their children views.

This excerpt is from the Rough Cuts version of the book and may not represent the final version of this material.

IN THIS CHAPTER

  • Introduction to Layouts
  • LinearLayout
  • Applying the Orientation Attribute
  • Applying Height and Width Attributes
  • Applying the Padding Attribute
  • Applying the Weight attribute
  • Applying the Gravity Attribute
  • Using the android:layout_gravity Attribute
  • RelativeLayout
  • Relative Layout Control Attributes
  • AbsoluteLayout
  • FrameLayout
  • TableLayout
  • TableLayout Operations
  • GridLayout
  • Screen Orientation Adaptations

Let’s start the chapter with an introduction to different layouts used in Android applications.

Introduction to Layouts

Layouts are basically containers for other items known as Views, which are displayed on the screen. Layouts help manage and arrange views as well. Layouts are defined in the form of XML files that cannot be changed by our code during runtime.

Table 3.1 shows the layout managers provided by the Android SDK.

Table 3.1 Android Layout Managers

Layout Manager

Description

LinearLayout

Organizes its children either horizontally or vertically

RelativeLayout

Organizes its children relative to one another or to the parent

AbsoluteLayout

Each child control is given a specific location within the bounds of the container

FrameLayout

Displays a single view, that is, the next view replaces the previous view and hence is used to dynamically change the children in the layout

TableLayout

Organizes its children in tabular form

GridLayout

Organizes its children in grid format

The containers or layouts listed in Table 3.1 are also known as ViewGroups as one or move Views are grouped and arranged in a desired manner through them. Besides the ViewGroups shown above, Android supports one more ViewGroup known as ScrollView which is discussed in Chapter 4, “Utilizing Resources and Media.”

  • + Share This
  • 🔖 Save To Your Account

Discussions

comments powered by Disqus