SlideShare una empresa de Scribd logo
1 de 35
Descargar para leer sin conexión
Android - Lesson 2




                             Daniela da Cruz

                        Universidade Lusófona do Porto


                            September, 2012


1 of 35
Android Application Overview

Activity Lifecycle

Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup

Layouts

XML Layout Attributes

Dimensions

Exercise

2 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
3 of 35
Android Application Overview


An Android application consists of various functionalities. Some
examples are editing a note, playing a music file, ringing an alarm, or
opening a phone contact.These functionalities can be classified into
four different Android components:




Every application is made up of one or more of these components.



4 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
5 of 35
Activity Lifecycle




6 of 35
Activity Lifecycle

Note the following:
• Changing the screen orientation destroys and recreates the activity
   from scratch.
• Pressing the Home button pauses the activity, but does not destroy
   it.
• Pressing the Application icon might start a new instance of the
   activity, even if the old one was not destroyed.
• Letting the screen sleep pauses the activity and the screen
   awakening resumes it. (This is similar to taking an incoming phone
   call.)


7 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
8 of 35
Activity



An Activity represents the visual representation of an Android
application.
Activities use Views and Fragments to create the user interface and
to interact with the user.

An Android application can have several Activities.




9 of 35
Fragments



Fragments are components which run in the context of an Activity.
Fragment components encapsulate application code so that it is easier
to reuse it and to support different sized devices.
Fragments are optional, you can use Views and ViewGroups directly in
an Activity but in professional applications you always use them to
allow the reuse of your user interface components on different sized
devices.




10 of 35
View and ViewGroup


Views are user interface widgets, e.g. buttons or text fields. Views
have attributes which can be used to configure their appearance and
behavior.
A ViewGroup is responsible for arranging other Views. ViewGroups is
also called layout managers.
ViewGroups can be nestled to create complex layouts. You should not
nestle ViewGroups too deeply as this has a negative impact on the
performance.




11 of 35
View and ViewGroup

The user interface for each component of your app is defined using a
hierarchy of View and ViewGroup objects.




The easiest and most effective way to define a layout is with an XML
file.
12 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
13 of 35
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. All of the layouts inherit from
ViewGroup (which inherits from View) so you can nest layouts.
The standard Layouts are:
• AbsoluteLayout
• FrameLayout
• LinearLayout
• RelativeLayout
• TableLayout


14 of 35
AbsoluteLayout (deprecated)

AbsoluteLayout is based on the simple idea of placing each control at
an absolute position. You specify the exact x and y coordinates on
the screen for each control.




15 of 35
FrameLayout

FrameLayout is designed to display a single item at a time. You can
have multiple elements within a FrameLayout but each element will be
positioned based on the top left of the screen. Elements that overlap
will be displayed overlapping.




16 of 35
LinearLayout

LinearLayout is a view group that aligns all children in a single
direction, vertically or horizontally.
You specify whether that line is vertical or horizontal using
android:orientation.




17 of 35
RelativeLayout (1)




RelativeLayout lays out elements based on their relationships with one
another, and with the parent container. RelativeLayout is very
powerful but the most complicated one, and we need several
properties to actually get the layout we want.




18 of 35
RelativeLayout (2)

These properties will layout elements relative to the parent
container:
• android:layout_alignParentBottom — Places the bottom of
   the element on the bottom of the container.
• android:layout_alignParentLeft — Places the left of the
   element on the left side of the container.
• android:layout_alignParentRight — Places the right of the
   element on the right side of the container.
• android:layout_alignParentTop — Places the element at the
   top of the container.


19 of 35
RelativeLayout (3)



(cont.)
• android:layout_centerHorizontal — Centers the element
   horizontally within its parent container.
• android:layout_centerInParent — Centers the element both
   horizontally and vertically within its container.
• android:layout_centerVertical — Centers the element
   vertically within its parent container.




20 of 35
RelativeLayout (4)



These properties allow you to layout elements relative to other
elements on screen.
• android:layout_above — Places the element above the specified
   element.
• android:layout_below — Places the element below the specified
   element




21 of 35
RelativeLayout (5)


(cont.)
• android:layout_toLeftOf — Places the element to the left of
   the specified element.
• android:layout_toRightOf — Places the element to the right of
   the specified element.

The value for each of these elements must be a reference to another
resource, in the form “@[+][package:]type:name”.




22 of 35
RelativeLayout (6)


These properties allow you to specify how elements are aligned in
relation to other elements.
• android:layout_alignBaseline — Aligns baseline of the new
   element with the baseline of the specified element.
• android:layout_alignBottom — Aligns the bottom of new
   element in with the bottom of the specified element.
• android:layout_alignLeft — Aligns left edge of the new
   element with the left edge of the specified element.




23 of 35
RelativeLayout (7)



(cont.)
• android:layout_alignRight — Aligns right edge of the new
   element with the right edge of the specified element.
• android:layout_alignTop — Places top of the new element in
   alignment with the top of the specified element.




24 of 35
RelativeLayout (8)




25 of 35
TableLayout

TableLayout organizes content into rows and columns. The rows are
defined in the layout XML, and the columns are determined
automatically by Android. This is done by creating at least one
column for each element.




26 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
27 of 35
XML Layout Attributes

At compile time, references to the resources are gathered into an
auto-generated wrapper class called R.java. The Android Asset
Packaging Tool (aapt) autogenerates this file.
The syntax for an ID, inside an XML tag is:

android:id="@+id/my_button"

The at-symbol (@) at the beginning of the string indicates that the
XML parser should parse and expand the rest of the ID string and
identify it as an ID resource. The plus-symbol (+) means that this is a
new resource name that must be created and added to the R.java file.


28 of 35
XML Layout Attributes



When referencing an Android resource ID, you do not need the
plus-symbol, but must add the android package namespace, like so:

android:id="@android:id/empty"

With the android package namespace in place, we’re now referencing
an ID from the android.R resources class, rather than the local
resources class.




29 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
30 of 35
Dimensions

A dimension is specified with a number followed by a unit of measure.
The following units of measure are supported by Android:
• dp — Density-independent Pixels: An abstract unit that is based on
   the physical density of the screen. These units are relative to a 160
   dpi (dots per inch) screen, on which 1dp is roughly equal to 1px.
   When running on a higher density screen, the number of pixels used
   to draw 1dp is scaled up by a factor appropriate for the screen’s dpi.
• sp — Scale-independent Pixels: This is like the dp unit, but it is
   also scaled by the user’s font size preference.
• pt — Points: 1/72 of an inch based on the physical size of the
   screen.


31 of 35
Dimensions



(cont.)
• px — Pixels: Corresponds to actual pixels on the screen. This unit
   of measure is not recommended because the actual representation
   can vary across devices.
• mm — Millimeters: Based on the physical size of the screen.
• in — Inches: Based on the physical size of the screen.




32 of 35
Layout

Android Application Overview
Activity Lifecycle
Basic Android User Interface components
   Activity
   Fragments
   View and ViewGroup
Layouts
XML Layout Attributes
Dimensions
Exercise
33 of 35
Exercise



Create your first Android application to understand the activity
lifecycle.
You should display a message as soon as an event (onCreate,
onStart, etc) is fired.

To display messages use the class android.widget.Toast.




34 of 35
Slides made using the help of:
• http://developer.android.com/
• Programming Android. Zigurd Mednieks, Laird Dornin, G. Blake
   Meike, Masumi Nakamura. O’Reilly Media. July 2011.
• The Android Developer’s Cookbook: Building Applications with the
   Android SDK. James Steele, Nelson To.
• http://www.learn-android.com




35 of 35

Más contenido relacionado

La actualidad más candente

Android apps development
Android apps developmentAndroid apps development
Android apps developmentRaman Pandey
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
android activity
android activityandroid activity
android activityDeepa Rani
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Androidma-polimi
 
View groups containers
View groups containersView groups containers
View groups containersMani Selvaraj
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestateOsahon Gino Ediagbonya
 
Android application-component
Android application-componentAndroid application-component
Android application-componentLy Haza
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - IntentDaniela Da Cruz
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversCodeAndroid
 
android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsRichard Hyndman
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesAhsanul Karim
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifestma-polimi
 

La actualidad más candente (20)

Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
android activity
android activityandroid activity
android activity
 
Android activity
Android activityAndroid activity
Android activity
 
Ppt 2 android_basics
Ppt 2 android_basicsPpt 2 android_basics
Ppt 2 android_basics
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
 
View groups containers
View groups containersView groups containers
View groups containers
 
Android Components
Android ComponentsAndroid Components
Android Components
 
Presentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestatePresentation on Android application life cycle and saved instancestate
Presentation on Android application life cycle and saved instancestate
 
Android application-component
Android application-componentAndroid application-component
Android application-component
 
Android Lesson 3 - Intent
Android Lesson 3 - IntentAndroid Lesson 3 - Intent
Android Lesson 3 - Intent
 
Android - Android Intent Types
Android - Android Intent TypesAndroid - Android Intent Types
Android - Android Intent Types
 
Android intent
Android intentAndroid intent
Android intent
 
Android: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast ReceiversAndroid: Intent, Intent Filter, Broadcast Receivers
Android: Intent, Intent Filter, Broadcast Receivers
 
android layouts
android layoutsandroid layouts
android layouts
 
Londroid Android Home Screen Widgets
Londroid Android Home Screen WidgetsLondroid Android Home Screen Widgets
Londroid Android Home Screen Widgets
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
 
Android UI
Android UIAndroid UI
Android UI
 
Android Components & Manifest
Android Components & ManifestAndroid Components & Manifest
Android Components & Manifest
 

Destacado

Intent in android
Intent in androidIntent in android
Intent in androidDurai S
 
Game Development with AndEngine
Game Development with AndEngineGame Development with AndEngine
Game Development with AndEngineDaniela Da Cruz
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating systemSalma Begum
 
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDI
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDIBeyond the Basics: An Overview of User LifeCycle and Managing Users with TDI
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDIStuart McIntyre
 
CS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineCS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineKatrin Becker
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAhsanul Karim
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - AndroidWingston
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)TECOS
 
Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Ted Liang
 
Layouts in android
Layouts in androidLayouts in android
Layouts in androidDurai S
 

Destacado (20)

Intent in android
Intent in androidIntent in android
Intent in android
 
Android intents
Android intentsAndroid intents
Android intents
 
Game Development with AndEngine
Game Development with AndEngineGame Development with AndEngine
Game Development with AndEngine
 
Android ppt
Android ppt Android ppt
Android ppt
 
Presentation on Android operating system
Presentation on Android operating systemPresentation on Android operating system
Presentation on Android operating system
 
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDI
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDIBeyond the Basics: An Overview of User LifeCycle and Managing Users with TDI
Beyond the Basics: An Overview of User LifeCycle and Managing Users with TDI
 
CS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual MachineCS Lesson: Introduction to the Java virtual Machine
CS Lesson: Introduction to the Java virtual Machine
 
Android Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver TutorialAndroid Application Component: BroadcastReceiver Tutorial
Android Application Component: BroadcastReceiver Tutorial
 
Input and Output Control
Input and Output ControlInput and Output Control
Input and Output Control
 
Android Ui
Android UiAndroid Ui
Android Ui
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Virtual machine subhash gupta
Virtual machine subhash guptaVirtual machine subhash gupta
Virtual machine subhash gupta
 
Virtual machine
Virtual machineVirtual machine
Virtual machine
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
The android activity lifecycle
The android activity lifecycleThe android activity lifecycle
The android activity lifecycle
 
Android ppt
Android pptAndroid ppt
Android ppt
 
02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)02 programmation mobile - android - (activity, view, fragment)
02 programmation mobile - android - (activity, view, fragment)
 
Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)Android Activity Transition(ShareElement)
Android Activity Transition(ShareElement)
 
Layouts in android
Layouts in androidLayouts in android
Layouts in android
 

Similar a Android Lesson 2

mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-TejamFandat
 
Android Apps Development Basic
Android Apps Development BasicAndroid Apps Development Basic
Android Apps Development BasicMonir Zzaman
 
Android training day 2
Android training day 2Android training day 2
Android training day 2Vivek Bhusal
 
Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1Isham Rashik
 
"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 #2Tadas Jurelevičius
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKnoldus Inc.
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docPalakjaiswal43
 
Android Introduction , Activity, Intent & Layout.pdf
Android Introduction , Activity, Intent & Layout.pdfAndroid Introduction , Activity, Intent & Layout.pdf
Android Introduction , Activity, Intent & Layout.pdfshamli5
 
Building a simple user interface lesson2
Building a simple user interface lesson2Building a simple user interface lesson2
Building a simple user interface lesson2Kalluri Vinay Reddy
 
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.pdfAbdullahMunir32
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Amit Saxena
 
DevFest Sul 2014 - Android 4 lazy iOS Devs
DevFest Sul 2014 - Android 4 lazy iOS DevsDevFest Sul 2014 - Android 4 lazy iOS Devs
DevFest Sul 2014 - Android 4 lazy iOS DevsJackson F. de A. Mafra
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsMaksym Davydov
 

Similar a Android Lesson 2 (20)

mobile application development -unit-3-
mobile application development  -unit-3-mobile application development  -unit-3-
mobile application development -unit-3-
 
Android Apps Development Basic
Android Apps Development BasicAndroid Apps Development Basic
Android Apps Development Basic
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
 
Notes Unit3.pptx
Notes Unit3.pptxNotes Unit3.pptx
Notes Unit3.pptx
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1
 
Android app development
Android app developmentAndroid app development
Android app development
 
Android User Interface
Android User InterfaceAndroid User Interface
Android User Interface
 
"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
 
Kotlin for Android App Development Presentation
Kotlin for Android App Development PresentationKotlin for Android App Development Presentation
Kotlin for Android App Development Presentation
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.doc
 
Android Introduction , Activity, Intent & Layout.pdf
Android Introduction , Activity, Intent & Layout.pdfAndroid Introduction , Activity, Intent & Layout.pdf
Android Introduction , Activity, Intent & Layout.pdf
 
Building a simple user interface lesson2
Building a simple user interface lesson2Building a simple user interface lesson2
Building a simple user interface lesson2
 
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
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1Android Tutorial For Beginners Part-1
Android Tutorial For Beginners Part-1
 
DevFest Sul 2014 - Android 4 lazy iOS Devs
DevFest Sul 2014 - Android 4 lazy iOS DevsDevFest Sul 2014 - Android 4 lazy iOS Devs
DevFest Sul 2014 - Android 4 lazy iOS Devs
 
Ui 5
Ui   5Ui   5
Ui 5
 
Lecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile AppsLecture 05. UI programming for Mobile Apps
Lecture 05. UI programming for Mobile Apps
 

Más de Daniela Da Cruz

Introduction to iOS and Objective-C
Introduction to iOS and Objective-CIntroduction to iOS and Objective-C
Introduction to iOS and Objective-CDaniela Da Cruz
 
Interactive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsInteractive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsDaniela Da Cruz
 
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Daniela Da Cruz
 
Android Introduction - Lesson 1
Android Introduction - Lesson 1Android Introduction - Lesson 1
Android Introduction - Lesson 1Daniela Da Cruz
 

Más de Daniela Da Cruz (6)

Introduction to iOS and Objective-C
Introduction to iOS and Objective-CIntroduction to iOS and Objective-C
Introduction to iOS and Objective-C
 
Games Concepts
Games ConceptsGames Concepts
Games Concepts
 
C basics
C basicsC basics
C basics
 
Interactive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical SystemsInteractive Verification of Safety-Critical Systems
Interactive Verification of Safety-Critical Systems
 
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...Comment Analysis approach for Program Comprehension (Software Engineering Wor...
Comment Analysis approach for Program Comprehension (Software Engineering Wor...
 
Android Introduction - Lesson 1
Android Introduction - Lesson 1Android Introduction - Lesson 1
Android Introduction - Lesson 1
 

Último

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 textsMaria Levchenko
 
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 MenDelhi Call girls
 
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 Servicegiselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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 MenDelhi Call girls
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Último (20)

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
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Android Lesson 2

  • 1. Android - Lesson 2 Daniela da Cruz Universidade Lusófona do Porto September, 2012 1 of 35
  • 2. Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 2 of 35
  • 3. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 3 of 35
  • 4. Android Application Overview An Android application consists of various functionalities. Some examples are editing a note, playing a music file, ringing an alarm, or opening a phone contact.These functionalities can be classified into four different Android components: Every application is made up of one or more of these components. 4 of 35
  • 5. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 5 of 35
  • 7. Activity Lifecycle Note the following: • Changing the screen orientation destroys and recreates the activity from scratch. • Pressing the Home button pauses the activity, but does not destroy it. • Pressing the Application icon might start a new instance of the activity, even if the old one was not destroyed. • Letting the screen sleep pauses the activity and the screen awakening resumes it. (This is similar to taking an incoming phone call.) 7 of 35
  • 8. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 8 of 35
  • 9. Activity An Activity represents the visual representation of an Android application. Activities use Views and Fragments to create the user interface and to interact with the user. An Android application can have several Activities. 9 of 35
  • 10. Fragments Fragments are components which run in the context of an Activity. Fragment components encapsulate application code so that it is easier to reuse it and to support different sized devices. Fragments are optional, you can use Views and ViewGroups directly in an Activity but in professional applications you always use them to allow the reuse of your user interface components on different sized devices. 10 of 35
  • 11. View and ViewGroup Views are user interface widgets, e.g. buttons or text fields. Views have attributes which can be used to configure their appearance and behavior. A ViewGroup is responsible for arranging other Views. ViewGroups is also called layout managers. ViewGroups can be nestled to create complex layouts. You should not nestle ViewGroups too deeply as this has a negative impact on the performance. 11 of 35
  • 12. View and ViewGroup The user interface for each component of your app is defined using a hierarchy of View and ViewGroup objects. The easiest and most effective way to define a layout is with an XML file. 12 of 35
  • 13. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 13 of 35
  • 14. 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. All of the layouts inherit from ViewGroup (which inherits from View) so you can nest layouts. The standard Layouts are: • AbsoluteLayout • FrameLayout • LinearLayout • RelativeLayout • TableLayout 14 of 35
  • 15. AbsoluteLayout (deprecated) AbsoluteLayout is based on the simple idea of placing each control at an absolute position. You specify the exact x and y coordinates on the screen for each control. 15 of 35
  • 16. FrameLayout FrameLayout is designed to display a single item at a time. You can have multiple elements within a FrameLayout but each element will be positioned based on the top left of the screen. Elements that overlap will be displayed overlapping. 16 of 35
  • 17. LinearLayout LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You specify whether that line is vertical or horizontal using android:orientation. 17 of 35
  • 18. RelativeLayout (1) RelativeLayout lays out elements based on their relationships with one another, and with the parent container. RelativeLayout is very powerful but the most complicated one, and we need several properties to actually get the layout we want. 18 of 35
  • 19. RelativeLayout (2) These properties will layout elements relative to the parent container: • android:layout_alignParentBottom — Places the bottom of the element on the bottom of the container. • android:layout_alignParentLeft — Places the left of the element on the left side of the container. • android:layout_alignParentRight — Places the right of the element on the right side of the container. • android:layout_alignParentTop — Places the element at the top of the container. 19 of 35
  • 20. RelativeLayout (3) (cont.) • android:layout_centerHorizontal — Centers the element horizontally within its parent container. • android:layout_centerInParent — Centers the element both horizontally and vertically within its container. • android:layout_centerVertical — Centers the element vertically within its parent container. 20 of 35
  • 21. RelativeLayout (4) These properties allow you to layout elements relative to other elements on screen. • android:layout_above — Places the element above the specified element. • android:layout_below — Places the element below the specified element 21 of 35
  • 22. RelativeLayout (5) (cont.) • android:layout_toLeftOf — Places the element to the left of the specified element. • android:layout_toRightOf — Places the element to the right of the specified element. The value for each of these elements must be a reference to another resource, in the form “@[+][package:]type:name”. 22 of 35
  • 23. RelativeLayout (6) These properties allow you to specify how elements are aligned in relation to other elements. • android:layout_alignBaseline — Aligns baseline of the new element with the baseline of the specified element. • android:layout_alignBottom — Aligns the bottom of new element in with the bottom of the specified element. • android:layout_alignLeft — Aligns left edge of the new element with the left edge of the specified element. 23 of 35
  • 24. RelativeLayout (7) (cont.) • android:layout_alignRight — Aligns right edge of the new element with the right edge of the specified element. • android:layout_alignTop — Places top of the new element in alignment with the top of the specified element. 24 of 35
  • 26. TableLayout TableLayout organizes content into rows and columns. The rows are defined in the layout XML, and the columns are determined automatically by Android. This is done by creating at least one column for each element. 26 of 35
  • 27. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 27 of 35
  • 28. XML Layout Attributes At compile time, references to the resources are gathered into an auto-generated wrapper class called R.java. The Android Asset Packaging Tool (aapt) autogenerates this file. The syntax for an ID, inside an XML tag is: android:id="@+id/my_button" The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to the R.java file. 28 of 35
  • 29. XML Layout Attributes When referencing an Android resource ID, you do not need the plus-symbol, but must add the android package namespace, like so: android:id="@android:id/empty" With the android package namespace in place, we’re now referencing an ID from the android.R resources class, rather than the local resources class. 29 of 35
  • 30. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 30 of 35
  • 31. Dimensions A dimension is specified with a number followed by a unit of measure. The following units of measure are supported by Android: • dp — Density-independent Pixels: An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen’s dpi. • sp — Scale-independent Pixels: This is like the dp unit, but it is also scaled by the user’s font size preference. • pt — Points: 1/72 of an inch based on the physical size of the screen. 31 of 35
  • 32. Dimensions (cont.) • px — Pixels: Corresponds to actual pixels on the screen. This unit of measure is not recommended because the actual representation can vary across devices. • mm — Millimeters: Based on the physical size of the screen. • in — Inches: Based on the physical size of the screen. 32 of 35
  • 33. Layout Android Application Overview Activity Lifecycle Basic Android User Interface components Activity Fragments View and ViewGroup Layouts XML Layout Attributes Dimensions Exercise 33 of 35
  • 34. Exercise Create your first Android application to understand the activity lifecycle. You should display a message as soon as an event (onCreate, onStart, etc) is fired. To display messages use the class android.widget.Toast. 34 of 35
  • 35. Slides made using the help of: • http://developer.android.com/ • Programming Android. Zigurd Mednieks, Laird Dornin, G. Blake Meike, Masumi Nakamura. O’Reilly Media. July 2011. • The Android Developer’s Cookbook: Building Applications with the Android SDK. James Steele, Nelson To. • http://www.learn-android.com 35 of 35