The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

The Classic Container Classes

Containers — sometimes referred to as layout managers — organize widgets on the screen. Containers position and size widgets based upon rules that you supply along with key device characteristics, such as available screen size.

Three containers have dominated Android app development since Android’s introduction in late 2007: LinearLayout, RelativeLayout, and TableLayout. This chapter focuses on those. Later chapters will explore other container classes, such as 2016’s ConstraintLayout.

Introducing the Sampler App

The Containers/Sampler sample project has a bunch of layout resources that this chapter will use to illustrate how these containers work.

If you were to run this sample app, you would see a series of tabs, with one layout displayed per tab:

Sampler App, As Initially Launched
Figure 109: Sampler App, As Initially Launched

We are not going to get into the Java code associated with this sample app in this chapter. That code relies on other topics, like fragments and the ViewPager widget, that we have not gotten to yet. We will come back to this sample app and see how the tabs were implemented then. For now, the focus is on the layout files showing specific techniques for using these classic containers.

RTL and Your Layouts

Most of the world’s languages are written left-to-right. So, in this paragraph, you read the letters and words starting from the left edge of a line across to the right edge.

Arabic and Hebrew, among others, are written right-to-left. The abbreviation “RTL” refers to these languages.

Originally, Android was focused purely on left-to-right (LTR) languages. As a result, you see attributes referring to things with respect to left and right (e.g., android:paddingLeft).

Slowly, Android improved its RTL support. In particular, starting with API Level 17 (Android 4.2), analogue attributes were added, replacing “left” with “start” and “right” with “end”. When using “start”/“end” attributes (e.g., android:paddingStart), “start” refers to where you start reading a line of text, and “end” refers to where you end reading a line of text:

Language Direction “Start” Means… “End” Means…
LTR Left Right
RTL Right Left

In general, we want the GUI to flow with the language direction. Things that you might have on the left with an LTR language usually go on the right with an RTL language, and so forth.

However, since these “start” and “end” attributes are new to API Level 17, you cannot use them on older devices. Sometimes, we will wind up either using the old “left”/“right” attributes or using both types of attributes, to cover all device versions.

We will revisit RTL language support a bit later in this chapter.

LinearLayout and the Box Model

The preview of this section was last seen in the Bermuda Triangle.

All Things Are Relative

The preview of this section is presently indisposed.

Tabula Rasa

The preview of this section is off trying to sweet-talk the Khaleesi into providing us with a dragon.

Hey, What About ConstraintLayout?

The preview of this section apparently resembled a Pokémon.

Turning Back to RTL

The preview of this section was lost in the sofa cushions.