User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.

Slides:



Advertisements
Similar presentations
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Advertisements

Android architecture overview
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
Basic, Basic, Basic Android. What are Packages? Page 346 in text Package statement goes before any import statements Indicates that the class declared.
Android GUI Project John Hurley CS 454. Android 1. Android Basics 2. Android Development 3. Android UI 4. Hello, World 5. My Project.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
App Development for Android Prabhaker Mateti. Development Tools (Android) Java – Java is the same. But, not all libs are included. – Unused: Swing, AWT,
Android Application Development with Java UPenn CS4HS 2011 Chris Murphy
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,
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
Android: Layouts David Meredith
Android Programming. Outline Preparation Create new project Build and Run a project Debug a project Deploy on devices.
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
1 Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources, Listener 10/9/2012 Y. Richard Yang.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
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.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
Chapter 2: Simplify! The Android User Interface
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.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
CE Applied Communications Technology Android lecture 2 - Structures Android File structure Resources Drawables Layout Values R Class Manifest Running.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
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.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Configuring Android Development Environment Nilesh Singh.
Android Boot Camp for Developers Using Java, Comprehensive: A Guide to Creating Your First Android Apps Chapter 2: Simplify! The Android User Interface.
1 Introducing Activity and Intent. 2 Memory LinearLayout, weight=2 LinearLayout, weight=1 TextView ListView.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
Building User Interfaces Basic Applications
Android 基本 I/O. 基本 I/O 介面元件 在此節中主要介紹常見的 I/O 使用者介 面元件 – Button, TextView, 以及 EditText , 學習者可以學會: – Android 的視窗表單設計 res/layout/main.xml – Android SDK –
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.
INTRODUCTION TO ANDROID. Slide 2 Introduction I take a top-down approach to describing an application’s anatomy.
Android 9: Layouts Kirk Scott.
Android Programming.
Lab7 – Appendix.
Android Programming - Features
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Application Development 1 6 May 2018
Android N Amanquah.
GUI Programming Fundamentals
Android Introduction Hello World.
Mobile Application Development BSCS-7 Lecture # 8
ITEC535 – Mobile Programming
HUJI Post PC Workshop 1 Introduction to Android Development Ari Sprung
תכנות ב android אליהו חלסצ'י.
Android GUI Project John Hurley CS 454.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
MultiUni Trần Vũ Tất Bình
Android GUI Project John Hurley CS 454.
Building User Interfaces Basic Applications
BMI Android Application will take weight and height from the users to calculate Body Mass Index (BMI) with the information, whether user is underweight,
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Sensor Programming
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

User Interface Android Applications

Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The visual content of the window is provided by a hierarchy of views. Each view controls a particular rectangular space within the window.

Hierarchy of Views Parent views contain and organize the layout of their children. Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond to user actions directed at that space.

View Hierarchy A view hierarchy is placed within an activity's window by the Activity.setContentView() method.Activity.setContentView()

View Group A ViewGroup is a special view that can contain other views (called children.) The view group is the base class for layouts and views container Some layout paramemeters: fill_parent, match_parent, wrap_content

Widgets The View class serves as the base for subclasses called "widgets," which offer fully implemented UI objects, like text fields and buttons. A widget is a View object that serves as an interface for interaction with the user.

Widgets: Ready-made views in Android buttons, text fields, scroll bars, menu items, check boxes, more

src/[package name]/[activity name].java package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } Notice that the class is based on the Activity class.Activity

The onCreate() method will be called by the Android system when your Activity starts — it is where you should perform all initialization and UI setup.onCreate() In there you will usually call setContentView(int) with a layout resource defining your UI setContentView(int)

Declaring Layout Your layout is the architecture for the user interface in an Activity. It defines the layout structure and holds all the elements that appear to the user. You can declare your layout in two ways: – Declare UI elements in XML – Instantiate layout elements at runtime

Declare UI elements in XML Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" />

res/values/strings.xml Hello World, HelloAndroid! Hello, Android

Hello World, HelloAndroid!

Instantiate layout elements at runtime Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.

src/[package name]/[activity name].java package com.example.helloandroid; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloAndroid extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Hello World, HelloAndroid!"); setContentView(tv); } }

Application Resources Common files in res/ directory: – drawable/icon.png: Icon for the program in launcher – layout/main.xml: User interface for main Activity – values/strings.xml: Any Strings appearing in UI Resources –separate program logic from “other stuff” Strings, images, UI layouts

res/layout/main.xml <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" />

Hello Android

XML files The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile.

Modified main.xml (1)

Modified main.xml (2)

Linear Layout

Identify the changes in main.xml

Modified main.xml <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent“ …

Identify changes in original main.xml

ID Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute.

Vertical LinearLayout to hold a TextView and a ButtonLinearLayout TextViewButton

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 our resources (in the R.java file).

Loading the XML Resource public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView.(R.layout.main_layout); }

R.java Eclipse combs through res/ directory, generating Java class to access resources in code. Examples:R.string., R.layout. Accessing resources through the R class lets Android determine the right resource to use

gen/ [Generated Java Files]/R.java /* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package com.example.helloandroid3; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; }