c5 - User Interface Architecture
c5 - User Interface Architecture
In this module, we will discover the fundamental design patterns of all android
applications. We will also learn about the different components of the android project which are
the src or source code, the auto generated codes and the included libraries. It is also in this
module that we will be demonstrating the “Hello World” program in android via video tutorial.
Objectives:
2. Understand the concept of Activity life cycle and its use in the android environment;
3. Test and run a simple android program in different screen sizes; and
USER INTERFACE 1
ARCHITECTURE
A. Standard View Layouts
A layout defines the visual structure for a user
interface (UI), such as the UI for an application or widget.
When designing layouts for Android, you’ll rarely want to
hardcode the value of button titles, labels, and other text
fields into the layout’s XML file. Instead, you define string
resources in a separate file and link to it from within the
layout. This extra layer of abstraction makes it possible to
reuse the same layout file with different string resources.
The advantage to declaring your UI in XML is that
it enables you to better separate the presentation of your
application from the code that controls its behaviour. Your
UI descriptions are external to your application code, which
means that you can modify or adapt it without having to
modify your source code and recompile.
In general, the XML vocabulary for declaring UI
elements closely follows the structure and naming of the
classes and methods, where element names correspond to
class names and attribute names correspond to methods. In
fact, the correspondence is often so direct that you can
guess what XML attribute corresponds to a class method,
or guess what class corresponds to a given XML element.
However, note that not all vocabulary is identical. In some
cases, there are slight naming differences.
Each layout file must contain exactly one root
element, which must be a View or ViewGroup object. Once
you've defined the root element, you can add additional
layout objects or widgets as child elements to gradually
build a View hierarchy that defines your layout.
When you compile a project, Android automatically
generates a View instance from each of your XML layout
files. Like String resources, these are accessed via the
special R class under the static layout variable. For
example, if you wanted to access the View instance created
from a file called activity_main.xml. Although before we
start talking about Android’s built-in layout schemes, it’s
important to understand how to set the size and position of
UI elements within a particular layout. The next three
sections show you how to define the dimensions, padding,
and margin of a UI element using various XML properties.
Common Layouts
Reference: