06 adapting ui for different screens and orientations

44
Andy Wigley @andy_wigley Matthias Shapiro @matthiasshap Adapting UI for Different Screens and Orientations WinRT Apps 29 April 2014 Building Apps for Windows Phone 8.1 Jump Start Building Windows Runtime Apps using C# and XAML

Upload: windowsphonerocks

Post on 04-Dec-2014

490 views

Category:

Technology


4 download

DESCRIPTION

Building Apps for Windows Phone 8.1 Jump Start . Videos at: http://channel9.msdn.com/Series/Building-Apps-for-Windows-Phone-8-1

TRANSCRIPT

Page 1: 06   adapting ui for different screens and orientations

Andy Wigley @andy_wigleyMatthias Shapiro @matthiasshap

Adapting UI for Different Screens and Orientations

WinRT Apps

29 April 2014

Building Apps for Windows Phone 8.1 Jump Start

Building Windows Runtime Apps using C# and XAML

Page 2: 06   adapting ui for different screens and orientations

In this module…Adapting UI for Different Screens and Orientations in Windows XAML apps…

Adapting to a diverse range of screen sizes and resolutionsRecap: Windows Phone 8 Silverlight approachWindows XAML approach in Windows Phone 8.1 Using emulators for testing different screen sizes and resolutionsProgramming for different screen sizes and resolutionsImagesResponsive UIDisplayInformation

Page 3: 06   adapting ui for different screens and orientations

Increasingly diverse Windows Phones

520 620 720 820 920 10201320 1520

*examples – many more devices in market

Page 4: 06   adapting ui for different screens and orientations

Used in different orientations

Page 5: 06   adapting ui for different screens and orientations

Apps need to cope with a diverse set of display sizes/resolutions

Page 6: 06   adapting ui for different screens and orientations

Recap – Windows Phone 8 approach

Page 7: 06   adapting ui for different screens and orientations

Today - Windows Phone 8.0

App is largely designed for one resolution and the OS applies (vector) scaling

1.0x 1.6x 1.5x 2.25x

480x800 480x800 480x853 480x853

*GDR3 added extra capability here

Page 8: 06   adapting ui for different screens and orientations

Start screen (e.g.) works differently – some devices display more content than others

Today - Windows Phone 8.0480px

80

0p

x

1080px

19

20

px

Page 9: 06   adapting ui for different screens and orientations

Sidebar: pixel sizes vary per device

Page 10: 06   adapting ui for different screens and orientations

“Raw” device pixels vary in size

Lumia 1520

1080px

19

20

px

Lumia 1320

720px

12

80

px

6”

Page 11: 06   adapting ui for different screens and orientations

“Raw” device pixels vary in size

Re-use of pieces of UI (e.g. templates) across platforms needs an abstraction that works for both

12

80

px

768px

Lumia 1520

800px

Dell Venue 8 Pro

12

80

px

Page 12: 06   adapting ui for different screens and orientations

Windows Phone 8.1 approach

Page 13: 06   adapting ui for different screens and orientations

Windows Runtime XAML on Windows Phone 8.1

7”

6”

5”

4.5”

Infinite virtual canvas

Upper bounds of X,Y vary depending on the deviceCalculated using• physical display

size• display resolution

Works for both today’s and future devicesSame system as Windows 8.1

x

y

Page 14: 06   adapting ui for different screens and orientations

Platform calculates a scale factor

12:38

width (inch)

pixelsscale factor =

pixels / width x platform constant

scale factor minimum of 1.0, rounded to nearest 0.2platform constant depends on viewing distance of device (phone/tablet/PC)

Page 15: 06   adapting ui for different screens and orientations

Scale factor is applied

12:38

width

heig

ht

“raw” pixels

12:38

width

heig

ht

“view” pixels

divide byscale factor

Page 16: 06   adapting ui for different screens and orientations

Same size, higher resolutions

12:38

540

96

05.5”

12:38

5.5”

720

12

80

12:38

5.5”

1080

19

20

450

800

“view” pixels

increasing scale factor

Page 17: 06   adapting ui for different screens and orientations

Same resolution, larger sizes

12:38

4.7”

1080

19

20

“view” pixels 368x686

12:38

5.5”

1080

19

20

450x800

12:38

6”

1080

19

20

491x873

increasing scale factor

Page 18: 06   adapting ui for different screens and orientations

Sidebar: the emulator is your friend

Page 19: 06   adapting ui for different screens and orientations

Emulator support for device sizes

Width Height Scale

400 666 1.2

400 666 1.2

384 640 2.0

400 711 1.8

450 800 2.4

490 872 2.2

Page 20: 06   adapting ui for different screens and orientations

How does an app provide the right experience?

Page 21: 06   adapting ui for different screens and orientations

1. Provide bitmap images to work with the scaling system

2. Build responsive UI that adapts to the usable screen size

3. Make use of DisplayInformation for granular display information

What does an app need to do?

Page 22: 06   adapting ui for different screens and orientations

1. Bitmaps

Page 23: 06   adapting ui for different screens and orientations

Bitmaps only scale so far…

12:38 12:38

multiply byscale factor

720px1

28

0p

x1080px

19

20

px

Page 24: 06   adapting ui for different screens and orientations

System for resolving resources

System attempts to use girl.scale-xxx.pngValue of xxx is based on the scale factorNo exact match? fallback to “next” best scale factorScale is one factor – system can also resolve based on scale, culture, theme, etc.

<Image Source="girl.png"/>

Page 25: 06   adapting ui for different screens and orientations

Resolution based on scale factor

12:38

scale factor

3.2

<Image Source="girl.png"/>

320<Image Source="girl.scale-400.png"/>

100 120 140 160 180 200 220 240 300 400

system defined scale factor “buckets”

Page 26: 06   adapting ui for different screens and orientations

Variable size images (e.g. background) – design for a high resolution (1080p) displayFixed size images

Creating images

size to get baselinewidth & height

ship 140% and 240%images (at least)

140

14

0

240

24

0

design for a 140%scaled device

Page 27: 06   adapting ui for different screens and orientations

Image scaling

demo

Page 28: 06   adapting ui for different screens and orientations

2. Responsive UI

Page 29: 06   adapting ui for different screens and orientations

Structure of a XAML page Frame

Page

Content (often Grid)

Page gives its entire space to its ContentYour root content panel will fill all the space (unless you take explicit steps)

Page 30: 06   adapting ui for different screens and orientations

Factors affecting XAML sizing

Top

Left

Many factors contribute to sizeGenerally avoid explicitly sizing elements – let the parent size the child

Page 31: 06   adapting ui for different screens and orientations

Proportional layout with Grid

Rows/columns – 3 types of sizing:star sizing

proportional: 1*/3* = 25%/75%

auto sizingsized to contentcontent can also have Max/Min widths and heights as limits

pixel sizinghard-coded size – avoid in most situations

auto1*2*

au

to1

*4

*7

*

Page 32: 06   adapting ui for different screens and orientations

Proportional layout with GridGrid

Grid

auto

auto

1*

1*1*

400

71

1

600

10

67

Page 33: 06   adapting ui for different screens and orientations

Additional space/additional content

Additional space generally given to controls which can display more contente.g. ItemsControls can display additional itemse.g. TextBlocks or RichTextBlocks can display more texte.g. content in ScrollViewers requires less scrollinge.g. more complex controls (e.g. Map) can take appropriate action

To simply scale the content as it was designed look to the ViewBox control

Page 34: 06   adapting ui for different screens and orientations

Additional space/additional content400

71

1

600

10

67

NB: MaxLines is a good mechanism for flexible limiting of text size

Page 35: 06   adapting ui for different screens and orientations

Additional space/scaled content

400

71

1

600

10

67

Page 36: 06   adapting ui for different screens and orientations

Responsive UI

demo

Page 37: 06   adapting ui for different screens and orientations

Responding to orientation changes

Display dimensions can change at runtime if your app supports portrait and landscape

Note: On Windows, it is customary to subscribe to the Page.SizeChanged event to detect orientation changes. SizeChanged does not fire on Windows Phone when orientation changes.

DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();

displayInfo.OrientationChanged += (s, e) => { DisplayOrientations orientation = displayInfo.CurrentOrientation;

// TODO: handle orientation change };

Page 38: 06   adapting ui for different screens and orientations

Orientation changes via Visual States

Define visual states for orientations & use Visual State Manager to animate between

auto

auto

auto

autoauto

Image (height =

x)

RichTextBlock

No C

onte

nt

In T

his

Colu

mn

(wid

th is

eff

ect

ively

zero

) auto

auto

auto

autoauto

Image (height = x)

RichTextBlock

No Content In This Row(height is effectively zero)

“Landscape”Visual State

animategrid.row 2 => 1grid.column 0

=> 1

Page 39: 06   adapting ui for different screens and orientations

Orientation Changes

demo

Page 40: 06   adapting ui for different screens and orientations

3. Display information

Page 41: 06   adapting ui for different screens and orientations

DisplayInformation class

DisplayInformation displayInfo = DisplayInformation.GetForCurrentView();

// NB: not all properties/events shown - take care with deprecated properties // such as ResolutionScale var nativeOrientation = displayInfo.NativeOrientation; var currentOrientation = displayInfo.CurrentOrientation; var rawPixelsPerViewPixel = displayInfo.RawPixelsPerViewPixel; var viewPixelsDPI = displayInfo.LogicalDpi; var rawDpiX = displayInfo.RawDpiX; var rawDpiY = displayInfo.RawDpiY;

e.g. Helpful to determine the native device resolution when downloading web-based images to match

Page 42: 06   adapting ui for different screens and orientations

DisplayInformation

demo

Page 43: 06   adapting ui for different screens and orientations

SummaryNew approach to layout for Windows Phone 8.1Shared with Windows 8.1Beyond uniform scaling of the UIDisplay size of the runtime device is unknown at design time

Apps need to be responsiveDesign for proportional layouts, not fixed sizesDesign for orientation changesTest on different device sizes/resolutions (including the emulators)Consider portrait/landscape and use techniques (such as VSM) to handle

“Raw” display information available to the subset of apps that require it

Page 44: 06   adapting ui for different screens and orientations

©2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.