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.
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:
This chapter focuses on those. Later chapters will explore other container
classes, such as 2016’s
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:
Figure 105: 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
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.
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.,
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”
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…|
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.
The preview of this section is presently indisposed.
The preview of this section is being chased by zombies.
The preview of this section was last seen in the Bermuda Triangle.
The preview of this section apparently resembled a Pokémon.
The preview of this section is en route to Mars.