Programming with Android: Introduction. Layouts. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Similar documents
Programming with Android: Introduction. Layouts. Luca Bedogni. Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Programming with Android: Layouts, Widgets and Events. Dipartimento di Scienze dell Informazione Università di Bologna

Graphical User Interfaces

Mobile Software Development for Android - I397

Android Layout Types

ANDROID USER INTERFACE

Let s take a display of HTC Desire smartphone as an example. Screen size = 3.7 inches, resolution = 800x480 pixels.

Android UI: Overview

User Interface Development. CSE 5236: Mobile Application Development Instructor: Adam C. Champion Course Coordinator: Dr.

Chapter 8 Positioning with Layouts

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University. Overview (Review)

Topics of Discussion

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University

Android Application Development

UI (User Interface) overview Supporting Multiple Screens Touch events and listeners

CS378 -Mobile Computing. User Interface Basics

Overview. What are layouts Creating and using layouts Common layouts and examples Layout parameters Types of views Event listeners

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android UI Development

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

Adapter.

Programming with Android: Android for Tablets. Dipartimento di Scienze dell Informazione Università di Bologna

Creating a Custom ListView

User Interface Development in Android Applications

South Africa

Laying Out Controls in Containers

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Sizing and Positioning

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

Introductory Android Development

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Comparative Study on Layout and Drawable Resource Behavior in Android for Supporting Multi Screen

Android HelloWorld - Example. Tushar B. Kute,

Computer Science E-76 Building Mobile Applications

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

Starting Another Activity Preferences

Fragment Example Create the following files and test the application on emulator or device.

Intents. Your first app assignment

Mobile Application Development Android

textview("layouts DSL is the only way") { textsize = 45f font = Fonts.MENLO }.lparams { gravity = Gravity.CENTER }

Basic GUI elements - exercises

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

When programming in groups of people, it s essential to version the code. One of the most popular versioning tools is git. Some benefits of git are:

Android Specifics. Jonathan Diehl (Informatik 10) Hendrik Thüs (Informatik 9)

Fragments. Lecture 11

Android Beginners Workshop

Arrays of Buttons. Inside Android

Building User Interface for Android Mobile Applications II

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Multiple devices. Use wrap_content and match_parent Use RelativeLayout/ConstraintLayout Use configuration qualifiers

Practical 1.ListView example

A view is a widget that has an appearance on screen. A view derives from the base class android.view.view.

Interaction with Android

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Introduction to Android Programming. Emmanuel Agu

Create Parent Activity and pass its information to Child Activity using Intents.

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

Android. Applications Activities Interface

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

CS371m - Mobile Computing. User Interface Basics

Mobile Computing Practice # 2c Android Applications - Interface

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

TPCT s College of Engineering, Osmanabad. Laboratory Manual SDL-II. Mobile Application Development (Android) For. Third Year Students (CSE)

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

Creating a User Interface

Upon completion of the second part of the lab the students will have:

Action Bar. (c) 2010 Haim Michael. All Rights Reserv ed.

Software Practice 3 Before we start Today s lecture Today s Task Team organization

Mobila applikationer och trådlösa nät, HI1033, HT2013


Praktikum Entwicklung Mediensysteme. Implementing a User Interface

CS 4518 Mobile and Ubiquitous Computing Lecture 2: Introduction to Android Programming. Emmanuel Agu

Manifest.xml. Activity.java

Lecture 14. Android Application Development

Simple Currency Converter

Tłumaczenie i adaptacja materiałów: dr Tomasz Xięski. Na podstawie prezentacji udostępnionych przez Victor Matos, Cleveland State University.

(c) Dr Sonia Sail LAJMI College of Computer Sciences & IT (girl Section) 1

ELET4133: Embedded Systems. Topic 15 Sensors

Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

Vienos veiklos būsena. Theory

Android. YÉÇàá. Victor Matos Cleveland State University

Chapter 5 Flashing Neon FrameLayout

else if(rb2.ischecked()) {

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

Android. Applications Activities Interface. Applications. Processes. Priorities. Activities

ActionBar. import android.support.v7.app.actionbaractivity; public class MyAppBarActivity extends ActionBarActivity { }

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Programmation Mobile Android Master CCI

05. RecyclerView and Styles

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

Programming Android UI. J. Serrat Software Design December 2017

Transcription:

Programming with Android: Introduction Layouts Luca Bedogni Marco Di Felice Dipartimento di Informatica: Scienza e Ingegneria Università di Bologna

Views: outline Main difference between a Drawable and a View is reaction to events Could be declared in an XML file Could also be declared inside an Activity Every view has a unique ID Use findviewbyid(int id) to get it Views can be customized 2

Some useful methods getleft() gettop() getmeasuredwidth() getmeasuredheight() getwidth() getheight() requestlayout() invalidate() 3

ViewGroup and layout ViewGroup is a view container It is responsible for placing other views on the display Every layout must extend a ViewGroup Every view needs to specify: android:layout_height android:layout_width A dimension or one of match_parent or wrap_content 4

Layouts Some layouts are pre-defined by Android Some of these are LinearLayout RelativeLayout TableLayout FrameLayout AbsoluteLayout A layout could be declared inside another layout 5

LinearLayout l l l Dispose views on a single row or column, depending on android:layout_orientation The orientation could also be declared via setorientation(int orientation) l orientation is one of HORIZONTAL or VERTICAL Has two other attributes: l l gravity weight 6

LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <!-- Also horizontal --> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/buttonstring1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/buttonstring2" /> </LinearLayout> 7

LinearLayout 8

LinearLayout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/buttonstring1" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="@string/buttonstring2" /> </LinearLayout> 9

LinearLayout 10

LinearLayout weight <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/buttonstring1" android:layout_weight="1" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/buttonstring2" android:layout_weight="2" /> </LinearLayout> 11

LinearLayout weight 12

LinearLayout gravity <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:text="@string/buttonstring1" android:layout_height="wrap_content" android:layout_weight="1" /> <Button android:id="@+id/button2" android:layout_width="match_parent" android:text="@string/buttonstring2" android:layout_height="wrap_content" android:layout_weight="2" android:layout_gravity="center_vertical" android:gravity="top center" /> </LinearLayout> 13

LinearLayout gravity 14

LinearLayout problem 15

RelativeLayout Disposes views according to the container or according to other views The gravity attribute indicates what views are more important to define the layout Useful to align views 16

RelativeLayout <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <EditText android:id="@+id/username" android:text="username" android:inputtype="text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_torightof="@+id/usernamelabel" > </EditText> <TextView android:id="@+id/usernamelabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/username" android:text="username" /> 17

RelativeLayout <EditText android:id="@+id/password" android:text="password" android:inputtype="textpassword" android:layout_below="@+id/username" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/username" android:layout_alignparentright="true" android:layout_torightof="@+id/usernamelabel" > </EditText> <TextView android:id="@+id/passwordlabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignbaseline="@+id/password" android:text="password" /> </RelativeLayout> 18

RelativeLayout 19

TableLayout As the name say, similar to a Table Has some attributes to customize the layout: android:layout_column android:layout_span android:stretchcolumns android:shrinkcolumns android:collapsecolumns Each row is inside a <TableRow> element 20

TableLayout <?xml version="1.0" encoding="utf-8"?> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/tablelayout"> <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content android:id="@+id/firstrow"> <Button android:id="@+id/button1 android:layout_width="wrap_content android:layout_height="wrap_content android:text="button" /> <Button android:id="@+id/button2 android:layout_width="match_parent" android:layout_height="match_parent" android:text="button" /> <Button android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="match_parent" android:text="button" /> </TableRow> 21

TableLayout <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/secondrow"> <Button android:layout_column="1" android:layout_span="2" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="button"> </Button> </TableRow> </TableLayout> 22

TableLayout 23

FrameLayout and AbsoluteLayout FrameLayout Adds an attribute, android:visibility Makes the user able to define layouts managing the visibility of views AbsoluteLayout Deprecated Specify position with x and y Pay attention to different resolutions 24

Adapters Used to visualize data Make a ViewGroup to interact with data Some methods: isempty() getitem(int position) getcount() getview() 25

AdapterView A ViewGroup subclass Its subchilds are determined by an Adapter Some subclasses: ListView GridView Spinner Gallery 26

ListView example public class HelloAndroidActivity extends Activity { @Override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.list); String[] data = {"First", "Second", "Third"}; ListView lv = (ListView)findViewById(R.id.list); lv.setadapter(new ArrayAdapter<String>(this, android.r.layout.simple_list_item_1, data)); } } <?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:id="@+id/list" /> 27

ListView 28

Other views/adapters Spinner, selection of multiple items Gallery, images ExpandableListView, list with hidden values TabWidget, tabbed layouts 29