Chapter 3. Getting to Know the Android User Interface
WHAT YOU WILL LEARN IN THIS CHAPTER
The various ViewGroups you can use to lay out your views
How to adapt to changes in screen orientation
How to manage screen orientation changes
How to create the UI programmatically
How to listen for UI notifications
In Chapter 2, you learned about the Activity
class and its life cycle. You learned that an activity is a means by which users interact with the application. However, an activity by itself does not have a presence on the screen. Instead, it has to draw the screen using Views and ViewGroups. In this chapter, you will learn the details about creating user interfaces in Android, how users interact with them. In addition, you will learn how to handle changes in screen orientation on your Android devices.
UNDERSTANDING THE COMPONENTS OF A SCREEN
In Chapter 2, you saw that the basic unit of an Android application is an activity. An activity displays the user interface of your application, which may contain widgets like buttons, labels, text boxes, and so on. Typically, you define your UI using an XML file (e.g., the main.xml
file located in the res/layout
folder), which may look like this:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" ...
Get Beginning Android™ Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.