SlideShare a Scribd company logo
1 of 21
Download to read offline
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

What's hot

Android android layouts
Android android layoutsAndroid android layouts
Android android layouts
perpetrotech
 

What's hot (20)

Android UI Patterns
Android UI PatternsAndroid UI Patterns
Android UI Patterns
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
Android Layout
Android LayoutAndroid Layout
Android Layout
 
Basic Android Layout
Basic Android LayoutBasic Android Layout
Basic Android Layout
 
Chapter 5 - Layouts
Chapter 5 - LayoutsChapter 5 - Layouts
Chapter 5 - Layouts
 
Chapter 10 - Views Part 2
Chapter 10 - Views Part 2Chapter 10 - Views Part 2
Chapter 10 - Views Part 2
 
Android Widget
Android WidgetAndroid Widget
Android Widget
 
Unit2
Unit2Unit2
Unit2
 
Android UI
Android UIAndroid UI
Android UI
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
 
Best Practices for Android UI by RapidValue Solutions
Best Practices for Android UI by RapidValue SolutionsBest Practices for Android UI by RapidValue Solutions
Best Practices for Android UI by RapidValue Solutions
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
10 asp.net session14
10 asp.net session1410 asp.net session14
10 asp.net session14
 
Build Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft AzureBuild Better Games with Unity and Microsoft Azure
Build Better Games with Unity and Microsoft Azure
 
Android UI Fundamentals part 1
Android UI Fundamentals part 1Android UI Fundamentals part 1
Android UI Fundamentals part 1
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
jQuery Mobile UI
jQuery Mobile UIjQuery Mobile UI
jQuery Mobile UI
 
Ui 5
Ui   5Ui   5
Ui 5
 
Android android layouts
Android android layoutsAndroid android layouts
Android android layouts
 
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & MenusLearn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
Learn Xamarin Absolute Beginners - Permissions, Building the App GUI & Menus
 

Similar to 01 08 - graphical user interface - layouts

Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
AbdullahMunir32
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
info_zybotech
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
Wingston
 
Windows phone 8 session 3
Windows phone 8 session 3Windows phone 8 session 3
Windows phone 8 session 3
hitesh chothani
 

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

mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
 
Android xml-based layouts-chapter5
Android xml-based layouts-chapter5Android xml-based layouts-chapter5
Android xml-based layouts-chapter5
 
Advance Android application development workshop day 2
Advance Android application development workshop day 2Advance Android application development workshop day 2
Advance Android application development workshop day 2
 
Android Layout.pptx
Android Layout.pptxAndroid Layout.pptx
Android Layout.pptx
 
Basics and different xml files used in android
Basics and different xml files used in androidBasics and different xml files used in android
Basics and different xml files used in android
 
Mobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdfMobile Application Development -Lecture 07 & 08.pdf
Mobile Application Development -Lecture 07 & 08.pdf
 
How to create ui using droid draw
How to create ui using droid drawHow to create ui using droid draw
How to create ui using droid draw
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 
Building a simple user interface lesson2
Building a simple user interface lesson2Building a simple user interface lesson2
Building a simple user interface lesson2
 
4.pptx
4.pptx4.pptx
4.pptx
 
Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 
Unit 2 LayoutTutorial.pptx
Unit 2 LayoutTutorial.pptxUnit 2 LayoutTutorial.pptx
Unit 2 LayoutTutorial.pptx
 
How to use data binding in android
How to use data binding in androidHow to use data binding in android
How to use data binding in android
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
 
Beginning Native Android Apps
Beginning Native Android AppsBeginning Native Android Apps
Beginning Native Android Apps
 
Android ui with xml
Android ui with xmlAndroid ui with xml
Android ui with xml
 
Windows phone 8 session 3
Windows phone 8 session 3Windows phone 8 session 3
Windows phone 8 session 3
 
"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2"Android" mobilių programėlių kūrimo įvadas #2
"Android" mobilių programėlių kūrimo įvadas #2
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
 

More from Siva Kumar reddy Vasipally (9)

01 11 - graphical user interface - fonts-web-tab
01  11 - graphical user interface - fonts-web-tab01  11 - graphical user interface - fonts-web-tab
01 11 - graphical user interface - fonts-web-tab
 
01 10 - graphical user interface - others
01  10 - graphical user interface - others01  10 - graphical user interface - others
01 10 - graphical user interface - others
 
01 07 -android programming basics (cont)
01  07 -android programming basics (cont)01  07 -android programming basics (cont)
01 07 -android programming basics (cont)
 
01 06 - android programming basics
01  06 - android programming basics01  06 - android programming basics
01 06 - android programming basics
 
01 05 - introduction xml
01  05 - introduction xml01  05 - introduction xml
01 05 - introduction xml
 
01 04 - android set up and creating an android project
01  04 - android set up and creating an android project01  04 - android set up and creating an android project
01 04 - android set up and creating an android project
 
01 03 - introduction to android
01  03 - introduction to android01  03 - introduction to android
01 03 - introduction to android
 
01 02 - introduction - adroid stack
01  02 - introduction - adroid stack01  02 - introduction - adroid stack
01 02 - introduction - adroid stack
 
01 01 - introduction to mobile application development
01  01 - introduction to mobile application development01  01 - introduction to mobile application development
01 01 - introduction to mobile application development
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.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.