Mobile Software Development for Android - I397

Slides:



Advertisements
Similar presentations
Rajab Davudov. What is a Layout ? A type of resource that defines what is drawn on the screen. A type of View class whose primary purpose is to organize.
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.
Android: Layouts David Meredith
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
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.
Android Basic XML Layouts Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
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.
Linear Layout, Screen Support, and Events. Linear Layout Supports 2 orientations: 1.Horizontal 2.Vertical I often get confused with how each orientation.
Resources and RelativeLayouts. Resources Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type.
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.
Android App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
MOBILE COMPUTING D10K-7D02 MC04: Layouts Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
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 View Stuff. TextViews Display text Display images???
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.
Building User Interfaces and Basic Applications Chapter 2 1.
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
CMPE419 Mobile Application Development Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren
Resources. Android Resources We’ve already talked about the different types of Android Resources DirectoryResource Type anim/XML files that define tween.
Open Handset Alliance.
Android Layouts 8 May 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.
Adapting to Display Orientation
Android User Interface: Understanding the Components of a Screen,
Linear Layout, Screen Support, and Events
Android Basic XML Layouts
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.
Politeknik Elektronika Negeri Surabaya
HNDIT2417 Mobile Application Development
SE4S701 Mobile Application Development
CIS 470 Mobile App Development
CS323 Android Model-View-Controller Architecture
Android Layout Basics Topics
CMPE419 Mobile Application Development
Mobile Computing With Android ACST 4550 Android Layouts
Building User Interfaces Basic Applications
Note Q) How to format code in Enclipse? A) Ctrl + i
Android Developer Fundamentals V2 Lesson 4
Android Developer Fundamentals V2
CIS 493/EEC 492 Android Sensor Programming
CIS 470 Mobile App Development
CIS 470 Mobile App Development
CMPE419 Mobile Application Development
Korea Software HRD Center
Building a Simple User Interface
CMPE419 Mobile Application Development
User Interface Screen Elements
CS 240 – Advanced Programming Concepts
Android Sensor Programming
Android Sensor Programming
Presentation transcript:

Mobile Software Development for Android - I397 IT College, Andres Käver, 2016-2017 Email: akaver@itcollege.ee Web: http://enos.itcollege.ee/~akaver/Android Skype: akaver

Layout fundamentals Basic layout Basic attributes Linear Relative Frame Table Basic attributes Size Margin vs padding Gravity

Layout Defines declaritively visual structure for app Takes into consideration screen properties size pixel density System calculates sizes and position for all UI elements

Layout

Layout - LinearLayout Arranges its children in single direction Orientation=“horizontal” Orientation=“vertical” <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> …ui elements… </LinearLayout>

Layout - RelativeLayout Elements are arranged relative to Parent UI element Sibling UI element <?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:layout_width="wrap_content" android:layout_height="200px" android:inputType="textMultiLine" android:ems="10" android:id="@+id/editText2" android:layout_alignParentTop="true" android:layout_alignParentStart="true" android:layout_alignParentEnd="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button4" android:layout_below="@+id/editText2" android:layout_alignParentEnd="true" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" android:id="@+id/button5" android:layout_alignBottom="@+id/button4" android:layout_toStartOf="@+id/button4" /> </RelativeLayout>

Layout - FrameLayout Allows to put child views on top of each other Specify order Layout gravity for positioning

Layout - TableLayout Rows and Columns Like Linear vertical nesting Linear horizontal Columns are aligned (by the widest in all the rows)

Basic attributes Used across all layouts Size Margin vs padding Gravity

Size Match_parent Wrap_content Use background tint for visual cues Xxxdp Density-independent pixel px = dp * density density = bucket(dpi/160) <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="New Text" android:id="@+id/textView2" /> </LinearLayout> android:background="#ff0000"

Size - dp

Margin vs padding

Margin vs padding No margin android:padding android:layout_margin layout_xxx prefix – deals with data from outside the view padding – inside the view

Gravity Android:layout_gravity Android:gravity Position of the view, regarding its parent Android:gravity Position of the content inside the view

Gravity <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="160dp" android:layout_height="160dp" android:gravity="center_horizontal" android:background="#ff0000" android:text="New Text" android:id="@+id/textView2" /> </LinearLayout> <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="160dp" android:layout_height="160dp" android:layout_gravity="center_horizontal" android:background="#ff0000" android:text="New Text" android:id="@+id/textView2" /> </LinearLayout>

Gravity Can be mixed and combined <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="160dp" android:layout_height="160dp" android:gravity="center_horizontal|bottom" android:layout_gravity="right" android:background="#ff0000" android:text="New Text" android:id="@+id/textView2" /> </LinearLayout>

LinearLayout What is LinearLayout? Gravity Weight Nested layout

LinearLayout

LinearLayout - Gravity

LinearLayout - Gravity

LinearLayout - Weight Additional way to specify dimensions (match_parent, wrap_content, xxxdp) Adds weights together Width is based on ratios (1+1=2 => ½ and ½) Can be mixed every way

LinearLayout - weightSum <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:weightSum="4"> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:background="#ff0000" android:text="Left side" android:id="@+id/textView2" /> <TextView android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:background="#00ff00" android:text="Right side" android:id="@+id/textView3" /> </LinearLayout

LinearLayout - nested <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/editText3" /> <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" android:id="@+id/button6"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" android:id="@+id/button7" /> </LinearLayout> </LinearLayout>

RelativeLayout What it is? Relative Positioning Relative Alignement Missing Views

RelativeLayout

RelativeLayout Relative Position Alignment To Parent Sibling

RelativeLayout - attributes

RelativeLayout Uses default parameters Top Left <?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/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> </RelativeLayout>

RelativeLayout No positions given Views are on top of each other <?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/editText2" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> <Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="New Button" /> </RelativeLayout>

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/editTextGreeting" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> <Button android:id="@+id/buttonOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editTextGreeting" android:layout_alignParentRight="true" android:text="OK" /> </RelativeLayout>

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/editTextGreeting" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> <Button android:id="@+id/buttonOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editTextGreeting" android:layout_alignParentRight="true" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/buttonOk" android:text="Cancel" android:id="@+id/buttonCancel" /> </RelativeLayout>

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/editTextGreeting" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> <Button android:id="@+id/buttonOk" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/editTextGreeting" android:layout_alignParentRight="true" android:text="OK" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/buttonOk" android:layout_below="@id/editTextGreeting" android:text="Cancel" android:id="@+id/buttonCancel" /> </RelativeLayout>

RelativeLayout Relative to sibling Relative to sibling Layout_above Layout_below Layout_toLeftOf Layout_toRightOf Relative to sibling Layout_alignTop Layout_alignBottom Layout_alignLeft Layout_alignRight Layout_alignBaseline

RelativeLayout Relative to parent Layout_alignParentTop Layout_alignParentBottom Layout_alignParentLeft Layout_alignParentRight Layout_centerHorizontal Layout_centerVertical Layout_centerInParent

RelativeLayout – Missing views Visibility=“invisible” View is still there, just invisible Placement of element is not changed Visibility=“gone” UI layout changes, view is really not there Defaults apply (top left) When changing visibility programmatically Layout_alignWithParentIfMissing=“true”

FrameLayout Allows to put views on top of each other Position child wiews with layout_gravity Layout_margin Usually used for placing images on top of other images Think of PictureFrame You can save one view by using on FrameLayout definition Android:foreground=“@drawable/somepicture” Control scaling of foreground (default is fill) Android:foregroundGravity=“top|left”

TableLayout What is TableLayout Spanning and skipping Shrinking, stretching and collapsing

TableLayout Specialized linear layout Rows Columns TableRow is always Layout_width=“match_parent” Layout_height=“wrap_content”

TableLayout <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:background="#ff0000" android:text="First" /> <TextView android:background="#00ff00" android:text="Second long" /> <TextView android:background="#0000ff" android:text="Third0" /> </TableRow> <TableRow> <TextView android:background="#ff0000" android:text="First long" /> <TextView android:background="#00ff00" android:text="Second" /> <TextView android:background="#0000ff" android:text="Third" /> </TableRow> </TableLayout>

TableLayout – skipping <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:background="#ffff00" android:text="Very long title" android:layout_column="1"/> </TableRow> <TableRow> <TextView android:background="#ff0000" android:text="First" /> <TextView android:background="#00ff00" android:text="Second long" /> <TextView android:background="#0000ff" android:text="Third0" /> </TableRow> <TableRow> <TextView android:background="#ff0000" android:text="First long" /> <TextView android:background="#00ff00" android:text="Second" /> <TextView android:background="#0000ff" android:text="Third" /> </TableRow> </TableLayout>

TableLayout – spanning <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TableRow> <TextView android:background="#ffff00" android:text="Very long title" android:layout_column="1" android:layout_span="2"/> </TableRow> <TableRow> <TextView android:background="#ff0000" android:text="First" /> <TextView android:background="#00ff00" android:text="Second long" /> <TextView android:background="#0000ff" android:text="Third0" /> </TableRow> <TableRow> <TextView android:background="#ff0000" android:text="First long" /> <TextView android:background="#00ff00" android:text="Second" /> <TextView android:background="#0000ff" android:text="Third" /> </TableRow> </TableLayout>

TableLayout – shrinking, stretching, collapsing

TableLayout – shrinking <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:shrinkColumns="1"> <TableRow> <TextView android:layout_column="0" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_span="3" android:background="#ffff00" android:text="Very long title" /> </TableRow> <TableRow> <TextView android:layout_height="match_parent" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:background="#ff0000" android:text="First" /> <TextView android:layout_height="match_parent" android:layout_marginRight="4dp" android:background="#00ff00" android:singleLine="false" android:text="Second long long long long long long long long long long long end" /> <TextView android:layout_height="match_parent" android:layout_marginRight="4dp" android:background="#0000ff" android:text="Third0" /> </TableRow> </TableLayout>

TableLayout – stretching <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:shrinkColumns="1" android:stretchColumns="*"> <TableRow> <TextView android:layout_column="0" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:layout_span="3" android:background="#ffff00" android:text="Very long title" /> </TableRow> <TableRow> <TextView android:layout_height="match_parent" android:layout_marginLeft="4dp" android:layout_marginRight="4dp" android:background="#ff0000" android:text="First" /> <TextView android:layout_height="match_parent" android:layout_marginRight="4dp" android:background="#00ff00" android:singleLine="false" android:text="Second long long long long long long long long long long long end" /> <TextView android:layout_height="match_parent" android:layout_marginRight="4dp" android:background="#0000ff" android:text="Third0" /> </TableRow> </TableLayout>

TableLayout – collapsing Android:collapseColumns=“*” * 1,2,4 Same as visibility=“gone”

Varia - performance

Varia – Hierarchy Viewer ViewServer Download ViewServer.java from https://github.com/romainguy/ViewServer Add INTERNET permission Enable ViewServer in your activity

Varia – Hierarchy Viewer Launch Android Device Monitor Window -> Open Perspective… -> Hierarchy View Select your running app from tree Click the icon “Load the view hierarchy into the tree view”