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.

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.
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!)
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,
@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
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: Application Layout Richard S. Stansbury 2015.
Introducing the Sudoku Example
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.
Mobile Programming Lecture 2 Layouts, Widgets, Toasts, and Event Handling.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
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.
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Using Android XML Resources.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
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.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
FramesLayout & Image View Pages FrameLayout is a ViewGroup that divides the screen into blocks of area each of which is supposed to holds a single.
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.
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
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.
Mobile Programming Lecture 4 Resources, Selection, Activities, Intents.
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.
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Android 9: Layouts Kirk Scott.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Android Introduction Hello World
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Android Introduction Hello World.
Mobile Application Development BSCS-7 Lecture # 8
ITEC535 – Mobile Programming
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Android Layout Basics Topics
CIS 470 Mobile App Development
Lecture 2 b: Android Layout Basics Topics
CMPE419 Mobile Application Development
Mobile Computing With Android ACST 4550 Android Layouts
Building User Interfaces Basic Applications
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Korea Software HRD Center
CMPE419 Mobile Application Development
Mobile Programmming Dr. Mohsin Ali Memon.
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

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. Code = write code using SDK with classes like LinearLayout, TextView, …… 2. XML = create XML files in res/Layout (i.e. main.xml) that contain Android XML view tags like, etc.

Lets look at this option first Option: XML Interface

XML Interface Creation  Generally, I would say if it is possible, doing XML would be better as it means a decoupling of design from Java code.  You can have both in your system….  Lets discuss this first.

The Layout --- the interface  Layouts defined with XML located in res/layout

The Layout-the interface  res/layout/main.xml = contains layout for interface <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" /> The above will create an interface in vertical (versus portrait) mode that fills the parent Both in width and write and wraps and content as necessary.

XML interface  it's a tree of XML elements,  Inspired by web authoring  Build up UI quickly  each node is the name of a View class (example is just one View element).  Create your own View ---extends  Each node can have multiple attributes  Look to API for details

XML interface   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.

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

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  I dragged and dropped an EditText view and a Button. Below I show you the corresponding code. res/layout/main2.xml <AbsoluteLayout xmlns:android=" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">

Besides drag and drop you can edit the xml file directly. Lets discuss some of the Android XML Interface related tags XML Interface tags

Control structure of interface Layout Tags

 Determines how the layout is structured.  Some 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.setOrientation() setGravity()LinearLayout.LayoutParams 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

LinearLayout XML tag  Visual creation of XML file  XML Attributes Attribute Name Related Method Description android:baselineAligned setBaselineAligned(boolean) When set to false, prevents the layout from aligning its children's baselines. android:baselineAlignedChildIndex setBaselineAlignedChildIndex(int) When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView). 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:measureWithLargestChild When set to true, all children with a weight will be considered having the minimum size of the largest child. android:orientation setOrientation(int) Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. android:weightSum Defines the maximum weight sum. android:baselineAlignedsetBaselineAligned(boolean)android:baselineAlignedChildIndexsetBaselineAlignedChildIndex(int)android:gravitysetGravity(int)android:measureWithLargestChildandroid:orientationsetOrientation(int)android:weightSum

Control structure of interface, but commonly a sub-area Related Layout Tags

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

Gallery  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(); } }); }

Making the elements of your GUI 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.  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…but, some are very common AttributeDescription layout_widthspecifies width of View or ViewGroup layout_heightspecifies height layout_marginTopextra space on top layout_marginBottomextra space on bottom side layout_marginLeftextra space on left side layout_marginRightextra space on right side layout_gravityhow child views are positioned layout_weighthow much extra space in layout should be allocated to View (only when in LinearLayout or TableView) layout_xx-coordinate layout_yy-coordinate