Chapter 3. Layouts: Being a layout
Weâve only scratched the surface of using layouts.
So far, youâve seen how to arrange views in a simple linear layout, but thereâs so much more that layouts can do. In this chapter weâll go a little deeper and show you how layouts really work. Youâll learn how to fine-tune your linear layouts. Youâll discover how to use frame layouts and scroll views. And by the end of the chapter, youâll learn that even though they might look a little different, all layoutsâand the views you add to themâhave more in common than you might think.
It all starts with a layout
As you already know, layout files are written in XML, and they let you define what your app looks like.
Each time you write a layout, you need to do three things:
Specify the type of layout.
You tell Android how you want any views (such as buttons and text views) to be arranged by specifying a type of layout. A linear layout, for example, arranges views in a linear column or row, one after another.
<LinearLayout ...> </LinearLayout>
Specify the views.
Each layout contains one or more views, which your app uses to display information or interact with the user.
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Click me" />
Tell an activity to use the layout.
You tell Android which activity uses the layout youâve just defined ...
Get Head First Android Development, 3rd Edition 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.