Chapter 3 Getting to Know the Android User Interface Design
Chapter 3 Getting to Know the Android User Interface Design
LEVEL 8
MOBILE APPLICATION
DEVELOPMENT
Course Coordinator
Ms. Shazia Ali
CHAPTER 3
Getting To Know The Android
User Interface
TOPICS TO BE COVERED
• Components of Screen
• Views and ViewsGroup
• Frame Layout, Linear Layout, Table Layout, Relative Layout
• Units of Measurement
• Scroll View
• Orientation
• Anchoring Views
• Action Bar
4
USER INTERFACE
• User interface in a mobile app refers to the visual and interactive elements that allow the user to interact with
the app
• It encompasses everything like layout, design, navigation, various input controls, images videos etc.
• The basic unit of an Android application is an activity, which displays the UI(User Interface) of your
application using Views and ViewGroups
• A view is a widget that has an appearance on screen
• Examples: buttons, labels, and text boxes
• A view derives from the base class android.view.View
• A ViewGroup (which is itself a special type of view) is to group views logically—such as a group of
buttons with a similar purpose
• Another type of ViewGroup is a Layout used to group and arrange views visually on the screen
• Also derives from android.view.ViewGroup
• FrameLayout, LinearLayout, TableLayout, GridLayout, RelativeLayout
DIFFERENCE BETWEEN VIEW&
5
VIEW GROUP
VIEW VIEW GROUP
1. View is the basic building block of the UI in 1. ViewGroup is a subclass of View and acts as a container
Android. for other Views.
2. It represents a single UI element or widget, such as a 2. It provides a way to organize and manage multiple
button, text field, image, or any other interactive or Views within a single container.
non-interactive element. 3. ViewGroup defines the layout structure and positioning
3. Views are responsible for rendering content, of its child Views.
handling user input, and responding to events. 4. Examples of ViewGroup subclasses include
4. Each View occupies a rectangular area on the screen LinearLayout, RelativeLayout, FrameLayout,
and can have properties like width, height, visibility, ConstraintLayout, etc.
background color, and more. 5. ViewGroup can contain other ViewGroups, creating a
5. Examples of View subclasses include TextView, hierarchy of nested containers.
Button, ImageView, EditText, etc. 6. ViewGroup manages the layout and measurement of its
6. Views can be arranged and structured within a child Views, determining how they are positioned and
layout using ViewGroup. sized within its boundaries.
LAYOUTS WITH VIEW & VIEWGROUP 6
Layouts are a type of View called a ViewGroup It’s not just the GUI
components that are a type of view. Under the hood, a layout is a special type
of view called a view group. All layouts are subclasses of the
android.view.ViewGroup class.
FRAMELAYOUT
• The FrameLayout is the most basic of the
Android layouts.
• FrameLayouts are built to hold one View
• The FrameLayout is used to help you
control the stacking of single views as the
screen is resized (or screens with different
resolutions)
• FrameLayout is a type of ViewGroup in
Android that allows you to stack multiple
child views on top of each other, with
each child occupying the entire area of
the FrameLayout.
• It is a simple and lightweight layout
container that is often used for displaying
overlapping views
7
HOW YOU DEFINE FRAMELAYOUT 8
<FrameLayout
xmlns:android=http://schemas.android.com/apk/res/android
android:layout_width="match_parent"
android:layout_height="match_parent" ...>
</FrameLayout>
FrameLayout
9
LINEAR LAYOUT (VERTICAL & HORIZONTAL)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
...
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:hint="@string/to" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:hint="@string/message" />
...
</LinearLayout>
COMMON ATTRIBUTES OF VIEWS &
VIEWGROUPS
12
TABLE LAYOUT
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1" />
</TableRow>
</TableLayout>
RELATIVE LAYOUT
• The RelativeLayout enables you to
specify how child views are
positioned relative to each other
• RelativeLayout has attributes that
enable it to align with another view.
These attributes are as follows:
➤ layout_alignParentTop
➤ layout_alignParentStart
➤ layout_alignStart
➤ layout_alignEnd
➤ layout_below
➤ layout_centerHorizontal
15
SYNTAX TO DEFINE RELATIVE LAYOUT 16
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/andr
oid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
…………..
</RelativeLayout>
GRID LAYOUT
17
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
ADAPTING TO DISPLAY 21
ORIENTATION
One of the key features of modern smartphones is their ability to switch screen
orientation, and Android is no exception. Android supports two screen orientations:
portrait and landscape. In general, you can employ two techniques to handle changes
in screen orientation:
• Anchoring—The easiest way is to “anchor” your views to the four edges of the
screen. When the screen orientation changes, the views can anchor neatly to the
edges.
• Resizing and repositioning—Whereas anchoring and centralizing are simple
techniques to ensure that views can handle changes in screen orientation, the
ultimate technique is resizing each and every view according to the current screen
orientation.
ANCHORING VIEWS 22
24
UNITS OF MEASUREMENT
25
ACTION BAR
■ Action Bar displays the application icon and
the activity title
■ The action bar is a component in Android
that provides a consistent user interface for
navigation, actions, and other options within
an application.
■ It typically appears at the top of the screen
and contains app branding, navigation icons,
and action items. The action bar is a crucial
part of the Material Design guidelines and
helps users understand and interact with the
app's functionality.
26
27
REVIEW QUESTIONS
1. What is View? Give Examples.
2. Compare View and ViewGroup.
3. Discuss the different types of Layouts in ViewGroup.
4. Differentiate between dp unit and px unit of measurement.
5. What is scroll view?.
6. What are the techniques to handle screen orientation?
7. List and Explain common attributes of Views and Views Group.
8. Explain briefly Table Layout and frame layout with syntax.
9. Explain briefly Relative Layout and Linear layout with syntax.
10. Explain using of Anchoring Views.