SUMMARY

In this chapter, you have learned how user interfaces are created in Android. You have also learned about the different layouts and views that you can use to build the UI in your Android application. Layouts views help to arrange the various views in the user interface of your Android application.

Finally, this chapter concluded with an overview of some of the specialized types of fragments that you can create in Android 3.0 for tablet applications. The three types of specialized fragments are ListFragment (for showing a list of items through a ListView), DialogFragment (for displaying as a dialog window), and PreferenceFragment (for displaying the shared preferences).

EXERCISES

1. What is the difference between the dp unit and the px unit? Which one should you use to specify the dimension of a view?

2. Why is the AbsoluteLayout not recommended for use?

3. How do you programmatically determine whether a RadioButton is checked?

4. Name the three specialized fragments you can use in your Android application.

Answers to the Exercises can be found in Appendix C.

WHAT YOU LEARNED IN THIS CHAPTER

TOPIC KEY CONCEPTS
LinearLayout Arranges views in a single column or single row.
AbsoluteLayout Enables you to specify the exact location of its children.
TableLayout Groups views into rows and columns.
RelativeLayout Enables you to specify how child views are positioned relative to each other.
FrameLayout An on-screen placeholder that you can use to display a single view.
ScrollView A special type of FrameLayout in that it enables users to scroll through a list of views that occupy more space than the physical display allows.
Unit of Measure Use the dp to specify the dimension of views, and sp for font size.
TextView
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
Button
<Button android:id="@+id/btnSave"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Save" />
ImageButton
<ImageButton android:id="@+id/btnImg1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/icon" />
EditText
<EditText android:id="@+id/txtName"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
CheckBox
<CheckBox android:id="@+id/chkAutosave"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="Autosave" />
RadioGroup and RadioButton
<RadioGroup android:id="@+id/rdbGp1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <RadioButton android:id="@+id/rdb1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Option 1" />
    <RadioButton android:id="@+id/rdb2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Option 2" />
    </RadioGroup>
ToggleButton
<ToggleButton android:id="@+id/toggle1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
Specialized types of fragments ListFragment, DialogFragment, and PreferenceFragment
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset