Developing the User Interface

Okay, it's time to start developing your user interface.

As stated previously, views in Android are the basic building blocks for user interface components. Anytime you implement a user interface component, such as a Layout, TextView, and so on, in the Android system, you are using a view.

So that Android knows how to lay out your view on the screen, however, you must configure a couple of attributes. These attributes, known in the Android SDK as LayoutParams, are

  • The layout_width attribute, which specifies the view's width
  • The layout_height attribute, which specifies the height

If you're using a static layout, these two attributes must be set in the XML layout. If you're creating views dynamically through code, the layout parameters must be set through Java code. Either way, you cannot do without them. I do not cover dynamic creation of views in this book. For more about dynamic creation of views, refer to the API samples that come with the Android SDK.

image If you forget to provide values for layout_width or layout_height, your Android application will crash when rendering the view. Thankfully, you are reminded of this sort of omission quickly when you test your application.

These attributes accept any pixel value or density-independent pixel value (density-independent pixels will be explained in Chapter 9) to specify their respective dimensions. However, ...

Get Android™ Tablet Application Development For Dummies® 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.