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

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

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

Android UI: Overview

ANDROID USER INTERFACE

Android UI Development

How to support multiple screens using android? Synopsis

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

CS 528 Mobile and Ubiquitous Computing Lecture 2a: Android UI Design in XML + Examples. Emmanuel Agu

Introductory Android Development

Laying Out Controls in Containers

Mobile Software Development for Android - I397

Sizing and Positioning

Android UI DateBasics

Praktikum Entwicklung Mediensysteme. Implementing a User Interface

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

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

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

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

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

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

Chapter 2 Welcome App

User Interface Development in Android Applications

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

Android Basics. Android UI Architecture. Android UI 1

CS 528 Mobile and Ubiquitous Computing Lecture 2: Intro to Android Programming Emmanuel Agu

Android Layout Types

CS 528 Mobile and Ubiquitous Computing Lecture 2: Intro to Android Programming Emmanuel Agu

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

Mobile Application Development Android

CS 403X Mobile and Ubiquitous Computing Lecture 3: Introduction to Android Programming Emmanuel Agu

ANDROID APPS DEVELOPMENT FOR MOBILE GAME

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

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

GUI Design for Android Applications

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

04. Learn the basic widget. DKU-MUST Mobile ICT Education Center

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

CS260 Intro to Java & Android 05.Android UI(Part I)

CS260 Intro to Java & Android 05.Android UI(Part I)

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

Styles, Style Sheets, the Box Model and Liquid Layout

Android Application Development

Chapter 8 Positioning with Layouts

CS371m - Mobile Computing. User Interface Basics

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

Android Beginners Workshop

CS378 -Mobile Computing. User Interface Basics

Designing and Implementing Android UIs for Phones and Tablets

Announcements. Android: n-puzzle Walkthrough. Tommy MacWilliam. Dynamic GUIs. ListViews. Bitmaps. Gameplay. Saving State. Menus

Chapter 5 Flashing Neon FrameLayout

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

ConstraintLayouts in Android

The drawable/tile empty.xml file

Creating a User Interface

Questions and Answers. Q.1) Which of the following is the most ^aeuroeresource hungry ^aeuroepart of dealing with activities on android?

Learning Android Canvas

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

Java & Android. Java Fundamentals. Madis Pink 2016 Tartu

Graphical User Interfaces

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Topics of Discussion

Mobile User Interfaces

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

BCA 6. Question Bank

O X X X O O X O X. Tic-Tac-Toe. 5COSC005W MOBILE APPLICATION DEVELOPMENT Lecture 2: The Ultimate Tic-Tac-Toe Game

Mobile Application Development - Android

EMBEDDED SYSTEMS PROGRAMMING UI and Android

Produced by. Mobile Application Development. Eamonn de Leastar David Drohan

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

CS 4330/5390: Mobile Application Development Exam 1

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

Android Application Development 101. Jason Chen Google I/O 2008

Charlie Collins Michael Galpin Matthias Käppler IN PRACTICE. Includes 91 Techniques SAMPLE CHAPTER MANNING

Android Development Crash Course

USER GUIDE. MADCAP FLARE 2017 r3. QR Codes

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

Fragments. Lecture 11

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

Mobile Programming Lecture 1. Getting Started

Introduction to User Interface Elements in Android

Mobile Application Workbench. SAP Mobile Platform 3.0 SP02

ANDROID APP DEVELOPMENT

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:

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

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

Layout and Containers

Better UI Makes ugui Better!

Programming with Android: Application Resources. Dipartimento di Scienze dell Informazione Università di Bologna

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

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

PSD to Mobile UI Tutorial

Android Programming (5 Days)

CSS Selectors. element selectors. .class selectors. #id selectors

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

Dreamweaver Tutorials Working with Tables

Mobile Development Lecture 10: Fragments

Android & iphone. Amir Eibagi. Localization

CIT BY: HEIDI SPACKMAN

BSCS 514- Computer Graphics. Course Supervisor : Dr. Humera Tariq Hands on Lab Sessions: Mr. Faraz Naqvi

Transcription:

International Journal of Innovative Research in Computer Science & Technology (IJIRCST) ISSN: 2347-5552, Volume 2, Issue 3, May - 2014 Comparative Study on Layout and Drawable Resource Behavior in Android for Supporting Multi Screen Ms. Sneha Mandavia Abstrac- this paper on Android deals with multi layout supports on various size of Android device. While writing an Android application developer should consider various size and type of device. So this paper on Android deals with certain points which developer should consider while design the layouts in Android mobile operating system. Index Terms- Android, PX unit, DP unit, mdpi I. INTRODUCTION Now a day various types of Android devices are available in markets which having different screen size, screen density, orientation, resolution, and Density-independent pixel (dp). As per Android documentation following is the concepts for each above terms. [1] [1] Screen size: Actual physical size i.e. small, medium, large, and extra large. [2] Screen density: quantity of pixels within a physical area, it referees to as dot per inch (dpi). Four types of densities are: ldpi (low), mdpi (medium), hdpi (high), and xhdpi (extra high) Density for Drawable i.e. Images drawable-ldpi: for low-density (ldpi) screens (~120dpi). drawable-mdpi: for medium-density (mdpi) screens (~160dpi). (This is the baseline density.) drawable-hdpi: for high-density (hdpi) screens (~240dpi). drawable-xhdpi: for extra high-density (xhdpi) screens (~320dpi). drawable- nodpi: for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density. [3] Orientation: shall be either landscape or portrait. Manuscript received May 05, 2014. Ms. Sneha Mandavia, FAculty of Department of Computer Science and Technology, Uka Tarsadia University, Tarsadia. - 394 350 [4] Resolution: The total number of physical pixels on a screen. [5] Density-independent pixel (dp): A virtual pixel unit that to use for layout dimensions or position in a density-independent way. On a 160 dpi screen Number of Pixel = Number of density independent pixel px = dp * (dpi / 160) E.g. If width of control is 20dp, and application running on 240dpi screen px = 20 * (240/160) = 30px Types of Layouts Supported by Android: [1] AbsoluteLayout: (This class was deprecated in API level 3.): 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. [2] LinearLayout: A layout that arranges its children into rows and columns. [3] RelativeLayout: sibling views can define their layout relative to another sibling view, which is referenced by the unique ID. You cannot have a circular dependency between the size of the RelativeLayout and the position of its children. [4] TableLayout: A layout that arranges its children into rows and columns. A TableLayout consists of a number of TableRow objects. [5] FrameLayout: Child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child (plus padding), Size of Android Control: FILL_PARENT: means that the view wants to be as big as its parent MATCH_PARENT: means that the view wants to be as big as its parent, minus the parent's padding, if any. FILL_PARENT renamed with MATCH_PARENT science API Level 8. WRAP_CONTENT: means that the view wants to be just large enough to fit its own internal content 53

Comparative Study on layout and drawable Resource Behavior in Android for Supporting Multi Screen Note: if developer does not want to give a control size as MATCH_PARENT or WRAP_CONTENT, then he can give absolute size also like 10px or 10dp. To show the layout s output, I tested the same layout on different features emulator. Device Name A B C Features Screen size: 240 x 320 (small) Screen density: 120 dpi Screen density type: ldpi Screen size: 720 x 1280 (X- Large) Screen density: 320 dpi Screen density type: xhdpi Screen size: 1280 x 800 (Large) Screen density: 160 dpi Screen density type: mdpi As we can see in output, the first control having size in dp, shall automatically resize with respect to device density. So as per equation control width dp shall converts in virtual pixel (vpx) is, vpx = dp * (dpi / 160) vpx = 120 * (120/160) vpx = 90px Control height shall, vpx = dp * (dpi / 160) vpx = 80 * (120/160) vpx = 60px Same snippet is tested in device B. II. COMPARISON BETWEEN PX AND DP UNIT px - corresponds to actual pixels on the screen. dp Density-independent Pixels It is a virtual pixel. Note: The compiler accepts both "dip" and "dp". Below example shows the difference between dp and px unit. Example having mainly two buttons, first button having hight and width in dp unit where as second button having hight and width in px unit. Below is the snippet for both controls. android:layout_width="120dp" android:layout_height="80dp" android:text="test" /> android:layout_width="120px" android:layout_height="80px" android:text="test" /> Above snippet first tested in device A. So here again dp unit shall automatically resize with respect to device density. So as per equation control width dp shall converts in virtual pixel (vpx) is, vpx = dp * (dpi / 160) vpx = 120 * (320/160) vpx = 240px Control height shall, vpx = dp * (dpi / 160) vpx = 80 * (320/160) vpx = 160px So in both the size of device, dp unit shall automatically converted to virtual pixel. But if we give px unit, remains as it is each density device. 54

International Journal of Innovative Research in Computer Science & Technology (IJIRCST) ISSN: 2347-5552, Volume 2, Issue 3, May - 2014 III. PREFERRED LAYOUT TYPE AbsoluteLayout: Below snippet shows the example for AbsoluteLayout. [4] <AbsoluteLayout android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_x="0dp" android:layout_y="5dp" android:text="button1" /> android:layout_x="245dp" android:layout_y="5dp" android:text="button2" /> </AbsoluteLayout> Above snippet was tested in device B. So here can see while using same snippet on different device, output was not proper. As control margin is absolute. What to do if we want to execute same layout on different device? Let s try with other layout type called RelativeLayout. [2] RelativeLayouts arrange the view with related to its sibling on its parents, RelativeLayout s property: android:layout_alignparentright android:layout_alignparentleft android:layout_alignparenttop android:layout_alignparentbottom android:layout_toleftof android:layout_torightof android:layout_above android:layout_below <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> android:text="button1" /> android:layout_alignparentright="true" android:text="button2" /> </RelativeLayout> Above snippet sets button2 at left side of layout. Same snippet was tested in device - A 55

Comparative Study on layout and drawable Resource Behavior in Android for Supporting Multi Screen And snippet was tested in device - A. Same snippet was tested in device B. Here we can see same snippet gave same output on different density size of device. [3] LinearLayout: name suggests, all the elements are displayed in a linear fashion, either Horizontally or Vertically and this behavior is set in android:orientation which is an attribute of the node LinearLayout. Another property android:layout_weight is use to give ratio for view s size. <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > android:layout_weight="1" android:text="button1" /> android:layout_weight="1" android:text="button2" /> </LinearLayout> Above code was again tested in two types of device, and it s seems that on both the device, layout s output is accordingly screen size and screen density. Snippet was tested in device A. Snippet was tested in device- B. 56

International Journal of Innovative Research in Computer Science & Technology (IJIRCST) ISSN: 2347-5552, Volume 2, Issue 3, May - 2014 Folder specification: Folder name density Screen size Image size drawable-ldpi 120(low) Small 0.75 x mdpi drawable-mdpi 160(medium) Medium Base size drawable-hdpi 240(large) Large 1.50 x mdpi drawable-xhdp i 320(extra large) Extra large 2 x mdpi So I both the size of device LinearLayout shows same output based on device size and density. IV. USING DRAWABLE RESOURCE dp unit is use to set control height and width, but if wants to set background resource, then we have to use drawable resource for a graphic that can be drawn to the screen.[5] Here I have shown the Android application structure having different drawable folder. So if developer wants to displays the image recourse as good as on any screen size having any density, he has to put a same image having different size but same name in different folder. So whenever user install same application on any device, based on device size and density application shall automatically pick the image from corresponding folder. Example: If I am executing my application in medium density device, so application shall pick the image from drawalbe-mdpi. So below snippet was tested on different screen size. <RelativeLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:layout_centerinparent="true" ndroid:background="@drawable/ic_launcher" /> </RelativeLayout> 57

Comparative Study on layout and drawable Resource Behavior in Android for Supporting Multi Screen layout was tested in device - A Layout was tested in device- B Layout was tested in device - C 58

International Journal of Innovative Research in Computer Science & Technology (IJIRCST) ISSN: 2347-5552, Volume 2, Issue 3, May - 2014 Output comparison on different screen size, Device Name Features Image pick from Screen size Screen density Screen density type A 240 x 320 (small) 120 dpi ldpi drawable-ldpi B 720 x 1280 (X- Large) 320 dpi xhdpi drawable-xhdpi C 1280 x 800 (Large) 160 dpi mdpi drawable-mdpi While executing the application device- c, Android picks the image from drawable-mdpi folder, as per device density device picks image from the right folder, but device size is large. So it s looks not good, as Android picks medium size image for large size device. So to remove this deficiency we have to add new resource i.e. creates a new folder called drawable-large-mdpi. drawable-large-mdpi: resource is use for the device which have medium density but large screen size, so we have to copy all the image from drawalbe-hdpi folder, and paste them to drawable-large-mdpi, so as a result we achieves the following output. So In this way developer can make n-number of resource for different screen size of device, whose density shall not match with the provided drawable. As per convention developer should create all size of images for each folder, but if some time developer avoid or miss to put any image in a folder, then Anroid is enough smart. It picks the image from another drawable folder. For example if developer made images for drwable-ldpi folder, and then he tries to execute his application on extra large screen, then extra large screen device picks the image from drwable-ldpi. But at that time on large screen output shall not as much good as low screen size device as drawable quality shall lose. V. USING SP UNIT Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference. [6] VI. CONCLUSION [1] When developer requires to give control s size, always prefer dp unit rather than px unit. [2] Avoid to use AbsoluteLayout while designs the layout. RelativeLayout is a great way to go. If you set Views' distances and sizes with dp, those distances in dp will be treated as pixels on an MDPI screen i.e. 160dpi screen, and they will be scaled so your layouts fill the space equally on LDPI and HDPI screens. [3] If possible create all size of drawable for all screen size and screen density device, so in future your application looks good on any size of device. 59

Comparative Study on layout and drawable Resource Behavior in Android for Supporting Multi Screen VII. REFERENCES [1]http://developer.android.com/guide/practices/screens_s upport.html [2]http://developer.android.com/guide/topics/ui/declaringlayout.html [3]http://stackoverflow.com/questions/16708078/what-is-d ifference-between-photoshop-px-and-android-dp [4]http://www.androidhive.info/2011/07/android-layouts-l inear-layout-relative-layout-and-table-layout/ [5]developer.android.com/guide/topics/resources/drawable -resource.html [6]http://developer.android.com/guide/topics/resources/mo re-resources.html#dimension Ms. Sneha Mandavia is a faculty of department of Computer Science and Technology, Uka Tarsadia University, Tarsadia. - 394 350. She is working as teaching assistant at same institute since last two years and teaching different subject like Mobile Application Development (Android), Web Application Development (J2EE), Object Oriented Software Engineering, Computer Graphics, Java Programming. She has one year experience in Android mobile application development. She has completed M.Sc. (IT) from J.P. Dawer Institute of Information Science & Technology, VNSGU, Surat. 60