User Interfaces: Part 1 (View Groups and Layouts).

Slides:



Advertisements
Similar presentations
Chapter 3 – Web Design Tables & Page Layout
Advertisements

Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
CE881: Mobile and Social Application Programming Simon M. Lucas Layouts.
Unlocking Android Chapter 4.  Understanding activities and views  Exploring the Activity lifecycle  Working with resources  Defining the AndroidManifest.xml.
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
User Interface Classes.  Design Principles  Views & Layouts  Event Handling  Menus  Dialogs.
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.
Layout and Control in UI The user interface (UI) is the graphical interface user can see and interact with your app comprising UI controls like textbox,
CS378 - Mobile Computing User Interface Basics MIKE!! LOOK HERE FOR intercepting the ListView items:
Presenting Lists of Data. Lists of Data Issues involved – unknown number of elements – allowing the user to scroll Data sources – most common ArrayList.
Android: Layouts David Meredith
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
Introduction to Android Programming Content Basic environmental structure Building a simple app Debugging.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
Android Development: Application Layout Richard S. Stansbury 2015.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Modify Android Objects Using.
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
PROG Mobile Java Application Development PROG Mobile Java Application Development Developing Android Apps: Components & Layout.
Chapter 9: Customize! Navigating with Tabs on a Tablet App.
Chapter 2: Simplify! The Android User Interface
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
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.
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
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.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
UI Resources Layout Resources String Resources Image Resources.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
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.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
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
BUILDING A SIMPLE USER INTERFACE. In this lesson, you create a layout in XML that includes a text field and a button. In the next lesson, your app responds.
Http :// developer. android. com / guide / topics / fundamentals. html.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android 9: Layouts Kirk Scott.
Chapter 2: Simplify! The Android User Interface
Lab7 – Appendix.
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Mobile Software Development for Android - I397
Mobile Application Development BSCS-7 Lecture # 8
Android 9: Layouts Kirk Scott.
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Android Introduction Hello Views Part 1.
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Android Programming Lecture 6
CMPE419 Mobile Application Development
Mobile Computing With Android ACST 4550 Android Layouts
Building User Interfaces Basic Applications
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Korea Software HRD Center
CMPE419 Mobile Application Development
Introduction to Android
Mobile Programmming Dr. Mohsin Ali Memon.
CS 240 – Advanced Programming Concepts
Android Sensor Programming
Presentation transcript:

User Interfaces: Part 1 (View Groups and Layouts)

Views Views are the basic building blocks of an Android graphical user interface. Class View (in package android.view ) is the base class for a collection of view subclasses. A view is an object that knows how to draw itself on the screen. A view is responsible for a rectangular area on the screen and handling events in that area Slide 2©SoftMoore Consulting

Types of Views Widget – an object that interacts directly with the user (e.g., button or check box) ViewGroup: a view that acts as a container to hold other View and ViewGroup objects (called its children). Layout – a ViewGroup that is responsible for positioning its children on the screen. Slide 3©SoftMoore Consulting

XML for a Layout Layouts can be declared in XML or created at runtime within the code, but the most common approach is to declare them in XML. Each layout file must contain exactly one root element, which must be a View or ViewGroup object, typically one of several common layouts. Additional layout objects or widgets are added as child elements to gradually build a View hierarchy that defines the layout. The XML file is placed in either the res/layout directory or the res/layout-land directory Slide 4©SoftMoore Consulting

Loading the XML Resource Each XML layout file is compiled into a View resource. Load the layout resource in the Activity.onCreate() by calling setContentView(), passing it the reference to your layout resource. Example public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);... } Slide 5©SoftMoore Consulting

Attributes Every View and ViewGroup object supports their own variety of XML attributes. Some attributes are specific to a View object (for example, TextView supports the textSize attribute) Attributes can also inherited by View classes that extend other View class. Attributes defined in the View class are common to all View objects (e.g., the id attribute). Layout attributes describe certain layout orientations of the layout. Slide 6©SoftMoore Consulting

The ID Attribute Any View object may have an integer ID associated with it to uniquely identify the View within the tree. Syntax: –The at-symbol ) 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. Some ID resources are provided by the Android framework and do not need the plus-symbol Slide 7©SoftMoore Consulting

LinearLayout A LinearLayout displays its child View elements in a linear direction, either vertically or horizontally. Children are stacked one after the other. –vertical: one child per row –horizontal: only one row high (height of the tallest child plus padding) Respects margins between children and the gravity (right, center, or left alignment) of each child. Creates a scrollbar if the length of the window exceeds the length of the screen. Slide 8©SoftMoore Consulting

Visualizing a LinearLayout Slide 9©SoftMoore Consulting

XML for a LinearLayout <LinearLayout xmlns:android= android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">... Slide 10©SoftMoore Consulting Text values should be specified in resource file strings.xml.

RelativeLayout A RelativeLayout is a ViewGroup that displays its child View elements in relative positions. The position of a child View can be specified as relative to sibling elements (such as to the left-of or below a given view) or relative to the parent RelativeLayout area (such as aligned to the bottom, left, or center). A RelativeLayout is a powerful utility for designing a user interface because it can eliminate nested view groups and keep the layout hierarchy flat, which improves performance. Nested LinearLayout groups can often be replaced by a single RelativeLayout. Slide 11©SoftMoore Consulting

Visualizing a RelativeLayout Slide 12©SoftMoore Consulting

XML for a RelativeLayout <RelativeLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText <Button android:layout_alignParentRight="true" android:layout_marginLeft="10dip" android:text="OK" /> Slide 13©SoftMoore Consulting (continued on next page) Text values should be specified in resource file strings.xml. Margin values should be specified in resource file dimens.xml.

XML for a RelativeLayout (continued) <Button android:text="Cancel" /> Slide 14©SoftMoore Consulting

TableLayout A TableLayout is a ViewGroup that displays its child View elements in rows and columns. The child views of a TableLayout are TableRow objects. –each TableRow defines a single row in the table The table will have as many columns as the row with the most cells. Each row has zero or more cells, each of which is defined by any kind of other View. –Cells of a row may be composed of a variety of View objects, like ImageView or TextView objects. –A cell may also be a ViewGroup object (e.g., you can nest another TableLayout as a cell). Slide 15©SoftMoore Consulting

TableLayout (continued) Table layouts are similar to HTML tables except that cells cannot span columns (but the use of weights can give a similar appearance). Columns can be marked as “stretchable” via the android attribute stretchColumns. To stretch all columns use a value of "*". Slide 16©SoftMoore Consulting

Example of a TableLayout Slide 17©SoftMoore Consulting

XML for a TableLayout <TableLayout xmlns:android=" android:layout_width="match_parent" android:layout_height="match_parent" android:stretchColumns="1"> <TextView android:layout_column="1" android:text="Open..." android:padding="3dip" /> <TextView android:text="Ctrl-O" android:gravity="right" android:padding="3dip" />... Slide 18©SoftMoore Consulting Text values should be specified in resource file strings.xml. Padding values should be specified in resource file dimens.xml.

GridView A GridView is a ViewGroup that displays its child View elements in a two-dimensional, scrollable grid. Example: a gallery of thumbnail pictures. The grid items are automatically inserted to the layout using an Adapter. Slide 19©SoftMoore Consulting

Visualizing a GridView Slide 20©SoftMoore Consulting

ListView A ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that’s placed into the list. The layout for a ListView involves two XML files, one for the overall layout of the list and another for laying out the individual rows. Slide 21©SoftMoore Consulting

Example: ListView Slide 22©SoftMoore Consulting ListViews will be covered in detail in a later section.

Relevant Links Layouts Building a Simple User Interface Table Layout How Android Draws Views Slide 23©SoftMoore Consulting