Download presentation
Presentation is loading. Please wait.
Published byAnabel McDowell Modified over 9 years ago
1
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Introduction to Android (Part 5) Layouts, Fonts, Toast
2
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 Android projects do not use the standard Java Layout Manager. Instead, for the Android, each type of container supports a particular strategy for laying out its components. There are also standard ‘layouts’ that you can overlay onto multiple items: LinearLayout In a LinearLayout components are arranged in a row horizontally or in a column vertically. If there is not enough space, the ones on the end (right or bottom) may not show at all. More complex layouts can be constructed by putting horizontal LinearLayout’s inside vertical a LinearLayout. This lets the designer set up a rough grid of components. Layouts
3
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 RelativeLayout The RelativeLayout holds components directly but arranges components based on specified relationships among the placements of components. For example, one component can be a specified distance below another component. Or, a component can have its left edge lined up with the left edge of another component. Relationships can be specified with the edges of the layout itself. The RelativeLayout is very flexible, but can be tricky to use. TableLayout While the TableLayout can hold components directly, it is more often used by putting TableRow’s inside and then putting components inside the TableRow’s. This has somewhat the same effect as putting LinearLayout’s inside LinearLayout’s with one major difference: the components in different rows are lined up in columns. Layouts
4
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 Although you can load your own font files into values resource folder, the Android OS only comes loaded with 3 basic fonts: MONOSPACE => fixed width font SERIF => fancier font (like Times Roman) SANS_SERIF => fancier font without feet You can use the following TypeFace styles with these fonts: TypeFace.NORMAL TypeFace.BOLD TypeFace.ITALIC TypeFace.BOLD_ITALIC Fonts
5
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 A Toast message is a simple Pop-up message that hovers above your current activity for a limited amount of time. A Toast message doesn’t receive any input, it only shows an output string. While it hovers, it only fills the amount of space required for the message and the current activity remains visible and interactive. Toasts automatically disappear after a timeout. You instantiate a Toast object by calling the makeText() methods This method takes three parameters: the application Context, the text message, and the duration for the toast (which can be either: Toast.LENGTH_SHORT or Toast.LENGTH_LONG). The makeText() method returns a properly initialized Toast object that you can then display by calling the show() method. Toasts
6
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 Toast messages can alert a user of an application state or provide timely messages for things like hints or debugging purposes. The following code would generate a toast message like the one shown below: Toast.makeText(getContext(), "Loading Doves... Please Wait", Toast.LENGTH_SHORT).show(); Toasts
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.