Time for action - creating the fruit icon

In order to display the various types of fruits as icons, we will need to create a layout XML file. Each icon in the GridView will be represented as an instance of this layout, in exactly the same way as list items are represented in a ListView. We create each item as an ImageView for the icon, with a TextView below it for the label.

  1. Create a file in the res/layout directory named fruit_item.xml.
  2. Declare the root element of the icon as a vertical LinearLayout:
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent">
  3. Create the ImageView element that will serve as our icon:
    <ImageView android:id="@+id/icon" ...

Get Android User Interface Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.