SlideShare a Scribd company logo
Android
Graphical User Interface
Agenda
Familiarize with the main types of GUI components
Layouts
Widgets
Menus
What is an XML Layout?
 An XML-based layout is a specification of the various UI components (widgets) and
the relationships to each other –and to their containers –all written in XML format.
Android considers XML-based layouts to be
resources, and as such layout files are stored in
the res/layout
directory inside your Android project.
Each XML file contains a tree of elements specifying a
layout of widgets and containers that make up one
View (shown later).
The attributes of the XML elements are properties,
describing how a widget should look or how a container
should behave.
Example:
If a Button element has an attribute value of
android:textStyle= "bold"
that means that the text appearing on the face of the
button should be rendered in a boldface font style.
Using @ in XML Layouts
 The button application introduced
<?xmlversion="1.0"encoding="utf-8"?>
<Buttonxmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/myButton"
android:text=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Anything you do want to use in your Java source needs an
android:id=“…”
The convention is to use @+id/nnn as the id value, where the nnn represents your
locally-unique name for the widget (eg. @+id/myButton).
Attaching Layouts to Java Code
 Assume res/layout/main.xml has been created. This layout could be
called by an application using the statement
setContentView(R.layout.main);
 Individual widgets, such as myButton could be accessed by the
application using the statement findViewByID(...) as in
Button btn= (Button) findViewById(R.id.myButton);
 Where R is a class automatically generated to keep track of resources
available to the application. In particular R.id... is the collection of
widgets defined in the XML layout.
Attaching Layouts to Java Code
 Attaching Listeners to the Widgets
 The button of our example could now be used, for instance a listener for the click event
could be written as:
btn.setOnClickListener(newOnClickListener() {
@Override
Public void onClick(View v) {
updateTime();
}
});
Private void updateTime() {
btn.setText(newDate().toString());
}
Android Layouts
 An Android layout is a class that handles arranging the way its
children appear on the screen.
 Anything that is a View (or inherits from View) can be a child of a
layout.
 The most common way to define layout and express the view
hierarchy is with an XML layout file.
There are five basic types of Layouts:
– Linear Layout
– Absolute Layout
– Table Layout
– Relative Layout
– Frame Layout
– Scroll View Layout
Frame Layout
 Frame Layout is the simplest type of layout object. It's basically a blank space on
your screen that you can later fill with a single object —for example, a picture that
you'll swap in and out.
 Views that you add to a Frame Layout is always anchored to the top left of the
layout.
<?xml version="1.0" encoding="utf‐8"?>
<AbsoluteLayout android:id="@+id/widget68"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android”>
<FrameLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="40px"
android:layout_y="35px"
>
<ImageView android:src = "@drawable/androidlogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</FrameLayout>
</AbsoluteLayout>
Linear Layout
 A Linear Layout is a View Group that will lay child View elements
 vertically or horizontally depending on the android:orientation attribute.
All children are stacked one after the other, so a
Vertical list will only have one child per row, no matter
how wide they are, and a
Horizontal list will only be one row high (the height of
the tallest child, plus padding).
Linear Layout
<?xml version="1.0" encoding="utf‐8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:layout_width="105px"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Button"
/>
</ LinearLayout >
The default orientation of Linear Layout is set to
horizontal.
 If you want to change its orientation to vertical, set the orientation
 attribute to vertical
Linear Layout
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.
com/apk/res/android"
>
Relative Layout
 A Relative Layout is a ViewGroup that allows you to layout child elements in
positions relative to the parent or siblings elements.
The following properties manage positioning of a widget respect to other
widgets:
 android:layout_above indicates that the widget should be placed above the
widget referenced in the property
 android:layout_below indicates that the widget should be placed below the
widget referenced in the property
android:layout_toLeftOf indicates that the widget should be placed to the left
of the widget referenced in the property
 android:layout_toRightOf indicates that the widget should be placed to the
right of the widget referenced in the property
Relative Layout
14
Relative Layout
 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Type here:"/>
<EditText
android:id="@+id/entry"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_backg
round"
android:layout_below="@id/label"/>
<Button
android:id="@+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/entry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:text="OK" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ok"
android:layout_alignTop="@id/ok"
android:text="Cancel" />
</RelativeLayout>
Table Layout
 A Table Layout is a View Group that that will lay child View elements into rows
and columns.
Table Layout
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.androi
d.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save..."
android:padding="3dip" />
<TextView
android:text="Ctrl-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<TableRow>
<TextView
android:layout_column="1"
android:text="Save As..."
android:padding="3dip" />
<TextView
android:text="Ctrl-Shift-S"
android:gravity="right"
android:padding="3dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090
" />
[………………………]
</TableLayout>
Absolute Layout
The Absolute Layout lets you specify the exact location of its children.
Consider the following UI defined in main.xml
the two Button views located at their specified positions using the android_layout_x
and android_layout_y attributes
Absolute Layout
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent” android:layout_height="fill_parent">
<Button
android:id="@+id/backbutton"
android:text="Back” android:layout_x="10px” android:layout_y="5px"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_x="10px” android:layout_y="110px"
android:text="First Name” android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="150px” android:layout_y="100px"
android:width="100px” android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_x="10px” android:layout_y="160px"
android:text="Last Name” android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:layout_x="150px” android:layout_y="150px"
android:width="100px"
android:layout_width="wrap_content” android:layout_height="wrap_content" />
</AbsoluteLayout>
Scroll View Layout
 A Scroll View is a special type of Frame Layout in that it allows
users to scroll through a list of views that occupy more space than
the physical display.
 The Scroll View can contain only one child view or View Group,
which normally is a Linear Layout.
 Note: Do not use a List View together with the Scroll View. The List
View is designed for showing a list of related information and is
optimized for dealing with large lists.
Scroll View
Questions?

More Related Content

PDF
01 09 - graphical user interface - basic widgets
PDF
Android Screen Containers & Layouts
PPTX
Android development session 3 - layout
PPT
android layouts
PDF
Android ui layout
PPTX
Android Training (Android UI)
PDF
Android layouts
PPT
View groups containers
01 09 - graphical user interface - basic widgets
Android Screen Containers & Layouts
Android development session 3 - layout
android layouts
Android ui layout
Android Training (Android UI)
Android layouts
View groups containers

What's hot (20)

PPT
Android UI Patterns
PDF
04 user interfaces
PPTX
Android Layout
PDF
Basic Android Layout
PDF
Chapter 5 - Layouts
PDF
Chapter 10 - Views Part 2
PPTX
Android Widget
PPTX
PPTX
Android UI
PDF
Advance Android Layout Walkthrough
PDF
Best Practices for Android UI by RapidValue Solutions
PPTX
Lesson 10
PPSX
10 asp.net session14
PDF
Build Better Games with Unity and Microsoft Azure
PDF
Android UI Fundamentals part 1
PPTX
Android apps development
PPTX
jQuery Mobile UI
PPTX
PPTX
Android android layouts
PPTX
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Android UI Patterns
04 user interfaces
Android Layout
Basic Android Layout
Chapter 5 - Layouts
Chapter 10 - Views Part 2
Android Widget
Android UI
Advance Android Layout Walkthrough
Best Practices for Android UI by RapidValue Solutions
Lesson 10
10 asp.net session14
Build Better Games with Unity and Microsoft Azure
Android UI Fundamentals part 1
Android apps development
jQuery Mobile UI
Android android layouts
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Ad

Similar to 01 08 - graphical user interface - layouts (20)

DOCX
Android xml-based layouts-chapter5
PPTX
UNIT5newpart2pptx__2024_11_13_09_52_11 (1).pptx
PPTX
Android Layout.pptx
PPTX
Unit 2 LayoutTutorial.pptx
PDF
MOBILE APPLICATION DEVELOPMENT
PPTX
06. Android Basic Widget and Container
PPTX
Lecture_On_AndroidApp_UserInterface.pptx
DOCX
How to create ui using droid draw
PDF
Mobile Application Development -Lecture 07 & 08.pdf
PPTX
Android User Interface
PPTX
Android programming basics
PPS
Android Workshop
PPTX
INTRODUCTION AND BASICS OF Android NOTES.pptx
PPTX
#7 Android Layouts.pptx
PDF
[Android] Basic Widgets and Containers
DOCX
Android practice of layout in application-chapter6
PPTX
03 layouts & ui design - Android
PPTX
Day 4 android bootcamp
PPTX
Introduction to android
Android xml-based layouts-chapter5
UNIT5newpart2pptx__2024_11_13_09_52_11 (1).pptx
Android Layout.pptx
Unit 2 LayoutTutorial.pptx
MOBILE APPLICATION DEVELOPMENT
06. Android Basic Widget and Container
Lecture_On_AndroidApp_UserInterface.pptx
How to create ui using droid draw
Mobile Application Development -Lecture 07 & 08.pdf
Android User Interface
Android programming basics
Android Workshop
INTRODUCTION AND BASICS OF Android NOTES.pptx
#7 Android Layouts.pptx
[Android] Basic Widgets and Containers
Android practice of layout in application-chapter6
03 layouts & ui design - Android
Day 4 android bootcamp
Introduction to android
Ad

More from Siva Kumar reddy Vasipally (9)

PDF
01 11 - graphical user interface - fonts-web-tab
PDF
01 10 - graphical user interface - others
PDF
01 07 -android programming basics (cont)
PDF
01 06 - android programming basics
PDF
01 05 - introduction xml
PDF
01 04 - android set up and creating an android project
PDF
01 03 - introduction to android
PDF
01 02 - introduction - adroid stack
PPTX
01 01 - introduction to mobile application development
01 11 - graphical user interface - fonts-web-tab
01 10 - graphical user interface - others
01 07 -android programming basics (cont)
01 06 - android programming basics
01 05 - introduction xml
01 04 - android set up and creating an android project
01 03 - introduction to android
01 02 - introduction - adroid stack
01 01 - introduction to mobile application development

Recently uploaded (20)

PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Machine learning based COVID-19 study performance prediction
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
TLE Review Electricity (Electricity).pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
August Patch Tuesday
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
1. Introduction to Computer Programming.pptx
PDF
Approach and Philosophy of On baking technology
PPTX
A Presentation on Artificial Intelligence
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Programs and apps: productivity, graphics, security and other tools
Heart disease approach using modified random forest and particle swarm optimi...
Machine learning based COVID-19 study performance prediction
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
TLE Review Electricity (Electricity).pptx
A comparative study of natural language inference in Swahili using monolingua...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Assigned Numbers - 2025 - Bluetooth® Document
August Patch Tuesday
Group 1 Presentation -Planning and Decision Making .pptx
Network Security Unit 5.pdf for BCA BBA.
1. Introduction to Computer Programming.pptx
Approach and Philosophy of On baking technology
A Presentation on Artificial Intelligence
SOPHOS-XG Firewall Administrator PPT.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MIND Revenue Release Quarter 2 2025 Press Release
gpt5_lecture_notes_comprehensive_20250812015547.pdf

01 08 - graphical user interface - layouts

  • 2. Agenda Familiarize with the main types of GUI components Layouts Widgets Menus
  • 3. What is an XML Layout?  An XML-based layout is a specification of the various UI components (widgets) and the relationships to each other –and to their containers –all written in XML format. Android considers XML-based layouts to be resources, and as such layout files are stored in the res/layout directory inside your Android project. Each XML file contains a tree of elements specifying a layout of widgets and containers that make up one View (shown later). The attributes of the XML elements are properties, describing how a widget should look or how a container should behave. Example: If a Button element has an attribute value of android:textStyle= "bold" that means that the text appearing on the face of the button should be rendered in a boldface font style.
  • 4. Using @ in XML Layouts  The button application introduced <?xmlversion="1.0"encoding="utf-8"?> <Buttonxmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/myButton" android:text="" android:layout_width="fill_parent" android:layout_height="fill_parent" /> Anything you do want to use in your Java source needs an android:id=“…” The convention is to use @+id/nnn as the id value, where the nnn represents your locally-unique name for the widget (eg. @+id/myButton).
  • 5. Attaching Layouts to Java Code  Assume res/layout/main.xml has been created. This layout could be called by an application using the statement setContentView(R.layout.main);  Individual widgets, such as myButton could be accessed by the application using the statement findViewByID(...) as in Button btn= (Button) findViewById(R.id.myButton);  Where R is a class automatically generated to keep track of resources available to the application. In particular R.id... is the collection of widgets defined in the XML layout.
  • 6. Attaching Layouts to Java Code  Attaching Listeners to the Widgets  The button of our example could now be used, for instance a listener for the click event could be written as: btn.setOnClickListener(newOnClickListener() { @Override Public void onClick(View v) { updateTime(); } }); Private void updateTime() { btn.setText(newDate().toString()); }
  • 7. Android Layouts  An Android layout is a class that handles arranging the way its children appear on the screen.  Anything that is a View (or inherits from View) can be a child of a layout.  The most common way to define layout and express the view hierarchy is with an XML layout file. There are five basic types of Layouts: – Linear Layout – Absolute Layout – Table Layout – Relative Layout – Frame Layout – Scroll View Layout
  • 8. Frame Layout  Frame Layout is the simplest type of layout object. It's basically a blank space on your screen that you can later fill with a single object —for example, a picture that you'll swap in and out.  Views that you add to a Frame Layout is always anchored to the top left of the layout. <?xml version="1.0" encoding="utf‐8"?> <AbsoluteLayout android:id="@+id/widget68" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android”> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_x="40px" android:layout_y="35px" > <ImageView android:src = "@drawable/androidlogo" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </FrameLayout> </AbsoluteLayout>
  • 9. Linear Layout  A Linear Layout is a View Group that will lay child View elements  vertically or horizontally depending on the android:orientation attribute. All children are stacked one after the other, so a Vertical list will only have one child per row, no matter how wide they are, and a Horizontal list will only be one row high (the height of the tallest child, plus padding).
  • 10. Linear Layout <?xml version="1.0" encoding="utf‐8"?> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <TextView android:layout_width="105px" android:layout_height="wrap_content" android:text="@string/hello" /> <Button android:layout_width="100px" android:layout_height="wrap_content" android:text="Button" /> </ LinearLayout > The default orientation of Linear Layout is set to horizontal.
  • 11.  If you want to change its orientation to vertical, set the orientation  attribute to vertical Linear Layout <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android. com/apk/res/android" >
  • 12. Relative Layout  A Relative Layout is a ViewGroup that allows you to layout child elements in positions relative to the parent or siblings elements. The following properties manage positioning of a widget respect to other widgets:  android:layout_above indicates that the widget should be placed above the widget referenced in the property  android:layout_below indicates that the widget should be placed below the widget referenced in the property android:layout_toLeftOf indicates that the widget should be placed to the left of the widget referenced in the property  android:layout_toRightOf indicates that the widget should be placed to the right of the widget referenced in the property
  • 14. 14 Relative Layout  <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Type here:"/> <EditText android:id="@+id/entry" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@android:drawable/editbox_backg round" android:layout_below="@id/label"/> <Button android:id="@+id/ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/entry" android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ok" android:layout_alignTop="@id/ok" android:text="Cancel" /> </RelativeLayout>
  • 15. Table Layout  A Table Layout is a View Group that that will lay child View elements into rows and columns.
  • 16. Table Layout <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.androi d.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1"> <TableRow> <TextView android:layout_column="1" android:text="Open..." android:padding="3dip" /> <TextView android:text="Ctrl-O" android:gravity="right" android:padding="3dip" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:text="Save..." android:padding="3dip" /> <TextView android:text="Ctrl-S" android:gravity="right" android:padding="3dip" /> </TableRow> <TableRow> <TextView android:layout_column="1" android:text="Save As..." android:padding="3dip" /> <TextView android:text="Ctrl-Shift-S" android:gravity="right" android:padding="3dip" /> </TableRow> <View android:layout_height="2dip" android:background="#FF909090 " /> [………………………] </TableLayout>
  • 17. Absolute Layout The Absolute Layout lets you specify the exact location of its children. Consider the following UI defined in main.xml the two Button views located at their specified positions using the android_layout_x and android_layout_y attributes
  • 18. Absolute Layout <AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent” android:layout_height="fill_parent"> <Button android:id="@+id/backbutton" android:text="Back” android:layout_x="10px” android:layout_y="5px" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_x="10px” android:layout_y="110px" android:text="First Name” android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_x="150px” android:layout_y="100px" android:width="100px” android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_x="10px” android:layout_y="160px" android:text="Last Name” android:layout_width="wrap_content" android:layout_height="wrap_content" /> <EditText android:layout_x="150px” android:layout_y="150px" android:width="100px" android:layout_width="wrap_content” android:layout_height="wrap_content" /> </AbsoluteLayout>
  • 19. Scroll View Layout  A Scroll View is a special type of Frame Layout in that it allows users to scroll through a list of views that occupy more space than the physical display.  The Scroll View can contain only one child view or View Group, which normally is a Linear Layout.  Note: Do not use a List View together with the Scroll View. The List View is designed for showing a list of related information and is optimized for dealing with large lists.