Creating Android user interfaces using layouts 1Android user interfaces using layouts.

Slides:



Advertisements
Similar presentations
ANDROID DEVELOPMENT KELLY MCBEAN. DEVELOPMENT ENVIRONMENT OVERVIEW Eclipse Standard IDE for Developing Android Applications Install: 1.Java (JDK) – Since.
Advertisements

Rajab Davudov. What is a Layout ? A type of resource that defines what is drawn on the screen. A type of View class whose primary purpose is to organize.
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Android User Interface
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
Filip Debelić What is it? Android is a mobile operating system (OS) based on the Linux kernel and currently developed by Google Android,
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
CS378 - Mobile Computing User Interface Basics MIKE!! LOOK HERE FOR intercepting the ListView items:
Android: Layouts David Meredith
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Introducing the Sudoku Example
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Modify Android Objects Using.
Chapter 3 Navigating a Project Goals & Objectives 1.Get familiar with the navigation of the project. How is everything structured? What settings can you.
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
CS5103 Software Engineering Lecture 08 Android Development II.
PROG Mobile Java Application Development PROG Mobile Java Application Development Developing Android Apps: Components & Layout.
Chapter 10: Move! Creating Animation
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Simplify! The Android User Interface
Chapter 5 Creating User Interfaces GOALS and OBJECTIVES Begin our application by creating our user interface. More than one way to create a user interface.
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
Chapter 2 The Android User Interface. Objectives  In this chapter, you learn to:  Develop a user interface using the TextView, ImageView, and Button.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Android Boot Camp for Developers Using Java, 3E
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Demo 02 StartUpScreen Display. We would like to include a button in our demo app to "do something". In the activity_main.xml we define a "Calc" button.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
MOBILE COMPUTING D10K-7D02 MC04: Layouts Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Android Drawing Units and The.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Building User Interfaces Basic Applications
Chapter 2 Building User Interfaces and Basic Applications.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 10: Move! Creating Animation 1 Android.
Building User Interfaces and Basic Applications Chapter 2 1.
Http :// developer. android. com / guide / topics / fundamentals. html.
CS371m - Mobile Computing User Interface Basics. UI Programming with Widgets Widget is an element in a Graphical User Interface (GUI) – not to be confused.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
Mobile Software Development for Android - I397 IT COLLEGE, ANDRES KÄVER, WEB:
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
Android apps development - Eclipse, Android SDK, and ADT plugin Introduction of.
CHAPTER 1 part 1 Introduction. Chapter objectives: Understand Android Learn the differences between Java and Android Java Examine the Android project.
Chapter 2: Simplify! The Android User Interface
Open Handset Alliance.
Adapting to Display Orientation
Mobile Software Development for Android - I397
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Politeknik Elektronika Negeri Surabaya
CIS 470 Mobile App Development
Android Programming Lecture 3
Android Layout Basics Topics
Mobile Computing With Android ACST 4550 Intro to Android, Part 3
Building User Interfaces Basic Applications
CIS 470 Mobile App Development
Mobile Programmming Dr. Mohsin Ali Memon.
CS 240 – Advanced Programming Concepts
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Creating Android user interfaces using layouts 1Android user interfaces using layouts

User interface defined in an XML file Android user interfaces are usually defined in XML files in the res folder During compilation the XML files generates a single Java class called R. – Set in the gen (Generated Java Files) folder Loaded in the Activity class – setContentView(R.layout.nameOfXmlFile) 2Android user interfaces using layouts

View and ViewGroup Organized using the Composite Design Pattern 3Android user interfaces using layouts

Screen densities Low density (ldpi): 120 dpi Medium density (mdpi): 160 dpi High density (hdpi): 240 dpi Extra high density (xhdpi): 320 dpi Used for units of measurement Used for pictures, icons, etc. – /res/drawableXx in your Android projects Android user interfaces using layouts4

Units of measurement Views sometimes needs measurements Some units of measurement – dp: density-independent pixel 160dp screen: 1dp ~ 1 pixel. Other screen densities: Scales automatically Recommended for specifying dimension of views – sp: scale-independent pixel Similar to dp, but scaled by users font preferences Recommended for specifying font sizes – pt: point 72pt = 1 inch = 2.54 cm on the physical screen – px: pixel Corresponds to the actual pixels on the screen. Not recommended, as the user interface may render differently on devices with different screen sizes – in: inches Not recommended – mm: millimeters Not recommended – Example: unitsOfMeasureMent – Source resources.html#Dimension Android user interfaces using layouts5

Different layouts LinearLayout – Horizontal or vertical AbsoluteLayout – Not recommended TableLayout – Table with rows and columns RelativeLayout – Child elements are positioned relative to each other FrameLayout – Placeholder to display a single view + title, etc. ScrollView – Enables the user to scroll through a list of views Android user interfaces using layouts6

Some XML view attributes Used in the layout XML files – The view is identified by this id. Used in the Java code – EditText number1field = (EditText) findViewById(R.id.number1); – android:layout-width=”fill_parent” The view will take as much space as the parent view allows. Renamed “match_parent” in API level 8 – android:layout-height=”wrap_content” The view will take as much space as needed to wrap the child (content) views – android:text=”some text” Sets a text in the view The text should be specified in the file /res/values/strings.xml for easy internationalization and localization. Android user interfaces using layouts7

Smartphone display orientation Smartphones have two display orientation – Portrait – Landscape – Switch as you turn the phone The emulators can also switch display orientation – Ordinary emulators: Press Ctrl + F11 – Geny Motion: use the “rotating phone” icon (right side) – Wait a moment for the layout to adapt to the new orientation 8Android user interfaces using layouts

Adapting to display orientation The onCreate() method is called whenever the display orientation changes – This gives your a chance to adapt to the new orientation Two techniques to handle changes in display orientation – Anchoring Anchor you views to the four edges of the display – Resizing and repositioning Resize views according to the display orientation 9Android user interfaces using layouts

Resizing and Repositioning Make two layout XML files for each Activity – Layout for portrait orientation In the folder layout – Layout for landscape orientation In the folder layout-land Both layout folders must be in the res folder Example: unitsOfMeasurement Android user interfaces using layouts10

Changing display orientation means loss of state Changing display orientation destroys and then recreates the activity – The activity’s state is lost Named views ( android:id ) will have their state persisted Other fields can be persisted using the methods – onSaveInstanceState(Bundle outState) Save the values in the Bundle – onRestoreInstanceState(Bundle savedInstanceState) Values from Bundle used to restore field values Example: collectWords Android user interfaces using layouts11

Controlling the display orientation Programmatically in the onCreate() method – setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ); Declaratively in the activity element of AndroidManifest.xml – android:screenOrientation=”landscape” on the activity element Example: collectWords – Documentation element.html#screen Android user interfaces using layouts12

Creating the User Interface Programmatically Usually and Activity’s user interface is defined in an XML file – Declaratively: Set at compile time However, the user interface can also be create in Java in the onCreate() method – Programmatically: Set at run-time – Very much like Java Swing 1.Create a layout object 2.Create View objects like Button, TextView, etc. objects with their own layout parameters 3.Add the view objects to the Activity 4.Add the layout object to the Activity Combination – Parts of the GUI is declared (the layout, etc.). Others parts are created programmatically Android user interfaces using layouts13