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,

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

Programming with Android: Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
 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.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Android GUI Project John Hurley CS 454. Android 1. Android Basics 2. Android Development 3. Android UI 4. Hello, World 5. My Project.
CS378 - Mobile Computing User Interface Basics MIKE!! LOOK HERE FOR intercepting the ListView items:
@2011 Mihail L. Sichitiu1 Android Introduction Hello World.
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
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: 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 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.
Android Fundamentals and Components Kris Secor Mobile Application Development.
Frank Xu Gannon University.  Linear Layout  Relative Layout  Table Layout.
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.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Presented By: Muhammad Tariq Software Engineer Android Training course.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
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.
ANDROID – A FIRST PROGRAM L. Grewe Using AndroidStudio –basic Android  Lets do a “Hello World Project”  Start up AndroidStudio (assume you have installed.
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
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.
You have to remember that  To create an AVD(Android Virtual Device)  The Structure of Android Project  XML Layout  The advantage of XML Layout  Android.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Lab7 – Appendix.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Open Handset Alliance.
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Android N Amanquah.
Android Introduction Hello World.
Mobile Application Development BSCS-7 Lecture # 8
Android Widgets 1 7 August 2018
ITEC535 – Mobile Programming
Android GUI Project John Hurley CS 454.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Android Lists and Fragments
CMPE419 Mobile Application Development
Android GUI Project John Hurley CS 454.
Building User Interfaces Basic Applications
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
CMPE419 Mobile Application Development
Mobile Programmming Dr. Mohsin Ali Memon.
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

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, button, checkbox, radio button, date, picker, and many more, and is presented in a variety of layouts. Every Android's user interface is composed of a hierarchical collection of View and ViewGroup objects. The View class is the base class of all UI controls or Widgets. Every visible UI control occupies an area on your screen and provides the point of interaction between you and the app through events like clicking, touching, and keying The ViewGroup class, on the other hand, is the invisible organizer(container) that provides a variety of UI layouts to position the various View objects on your screen. For ex., you may arrange the UI controls one above another in a linear fashion by LinearLayout layout, or relative to each other by RelativeLayout layout. ViewGroup class is also derived from View class, you can have a ViewGroup object (child) nested in another ViewGroup object (parent), and each can take on different layouts.

Linear Layout Orientation

Relative layout

Table Layout

Frame Layout A FrameLayout is a ViewGroup that divides the screen into blocks of area each of which is supposed to holds a single child View

Buttons and Icon

TextView and EditText

Check Box and radio Button

ToggleButton A ToggleButton is an on/off switch. It can be used in turning on and off features like vibration mode, silent mode, WiFi connection

A Spinner is just a fanciful name for the all-too-familiar dropdown list.

Progress Bar

DatePicker and TimePicker

ListView A ListView is a ViewGroup that displays a list of scrollable items from a data source via an Adapter. An Adapter acts as the middle man to pull rows of data from a data source such as an array or database, and to convert each row of data into a View which is then inserted into the ListView.

UI layouts LinearLayout RelativeLayout TableLayout FrameLayout RadioGroup ListView GridView UI Controls Button TextView EditText CheckBox RadioButton ToggleButton Spinner AutoCompleteTextView Progress Bar Pickers ImageView

Android Interfaces: Code or XML Two ways to create UI of your App: Write code using SDK with classes like LinearLayout, TextView, …… Create XML files in res/Layout (i.e. main.xml) where Android XML view tags like, etc. View: drawable object, controls UI contains a hierarchy of Views View is a class, subclassed by the drawable objects in the UI

Programmatic UI package demo; import android.app.Activity; import android.widget.TextView; import android.os.Bundle; public class AndroidDemo extends Activity { /** Called when the activity is first created. public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Activity is a subclass of context, so the TextView takes this as a parameter TextView tv = new TextView(this); tv.setText("Hello"); setContentView(tv); }

Manual Declarative UI main.xml Layout File: <TextView xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" strings.xml resource file: Hello Again AndroidDemo

Layout xml xmlns:android XML namespace declaration that tells the Android tools that you are going to refer to common attributes defined in the Android namespace. The outermost tag in every Android layout file must have this attribute. android:layout_width This attribute defines how much of the available width on the screen this View should consume. As it's the only View so you want it to take up the entire screen, which is what a value of "fill_parent" means. android:layout_height This is just like android:layout_width, except that it refers to available screen height. android:text This sets the text that the TextView should display. In this example, you use a string resource instead of a hard-coded string value. The hello string is defined in the res/values/strings.xml file.

XML interface Layouts defined with XML located in res/layout

What’s R? /* 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 demo; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class id { public static final int textview=0x7f050000; } 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; }

Android Event Handlers From the code file for the activity: Button ok = (Button) findViewById(R.id.button1); ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CharSequence s = et.getText(); tv.setText("Welcome, " + s); } });

Using Eclipse IDE to Visually Create XML file Visual creation of XML file Create New->Other->Android->XML file- Select for layout type Play with it…. drag and drop

Visually Creating XML interface res/layout/main2.xml <AbsoluteLayout xmlns:android=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">

Layout Tags LinearLayout A Layout that arranges its children in a single column or a single row. The direction of the row can be set by calling setOrientation(). You can also specify gravity, which specifies the alignment of all the child elements by calling setGravity() or specify that specific children grow to fill up any remaining space in the layout by setting the weight member of LinearLayout.LayoutParams. The default orientation is horizontal. AbsoluteLayout A layout that lets you specify exact locations (x/y coordinates) of its children. Absolute layouts are less flexible and harder to maintain than other types of layouts without absolute positioning. RelativeLayout FrameLayout TableLayout

ListView A view that shows items in a vertically scrolling list. Attributes android:divider Drawable or color to draw between list items. android:dividerHeight Height of the divider. android:entries Reference to an array resource that will populate the ListView. android:footerDividersEnabled When set to false, the ListView will not draw the divider before each footer view. android:headerDividersEnabled When set to false, the ListView will not draw the divider after each header view.

 A view that shows items in a center-locked, horizontally scrolling list.  The default values for the Gallery assume you will be using Theme_galleryItemBackground as the background for each View given to the Gallery from the Adapter. If you are not doing this, you may need to adjust some Gallery properties, such as the spacing. Theme_galleryItemBackground Attributes  android:animationDuration setAnimationDuration(int) Sets how long a transition animation should run (in milliseconds) when layout has changed. android:animationDurationsetAnimationDuration(int)  android:gravity setGravity(int) Specifies how to place the content of an object, both on the x- and y-axis, within the object itself. android:gravitysetGravity(int)  android:spacing setSpacing(int) android:spacingsetSpacing(int)  android:unselectedAlpha setUnselectedAlpha(float) Sets the alpha on the items that are not selected. android:unselectedAlphasetUnselectedAlpha(float)

Code—setting up public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Gallery gallery = (Gallery) findViewById(R.id.gallery); gallery.setAdapter(new ImageAdapter(this)); gallery.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show(); } }); }

Views and ViewGroups An Activity can contain views and ViewGroups. android.view.View.* = base class for all Views. example sub-classes include: TextView, ImageView, etc. android.view.ViewGroup = Layout for views it contains, subclasses include android.widget.LinearLayout android.widget.AbsoluteLayout android.widget.TableLayout android.widget.RelativeLayout android.widget.FrameLayout android.widget.ScrollLayout

LinearLayout ( or android.widget.LinearLayout) arranges by single column or row. child views can be arranged vertically or horizontally. <LinearLayout xmlns:android=" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Text View android:layout_width=“fill_parent” android:layout_height=“wrap_content”

Linear Layout Example

LinearLayout attributes You can set either in XML or with set*() methods by programing. i.e. Xml android:orientation=“vertical” code (ll is LinearLayout instance) ll.setOrientation(VERTICAL);

Each View or ViewGroup can have its own set of attributes