60
Developers

115 - Android Design for UI Developers (1)

Embed Size (px)

DESCRIPTION

android

Citation preview

Page 1: 115 - Android Design for UI Developers (1)

Developers

Page 2: 115 - Android Design for UI Developers (1)

13

Android Designfor UI Developers

Page 3: 115 - Android Design for UI Developers (1)

+Nick Butcher+Roman Nurik

Page 4: 115 - Android Design for UI Developers (1)

4

Android Design in Action

www.androiddesigninaction.com

Page 5: 115 - Android Design for UI Developers (1)

Agenda

5

AppNavigation

Lateral navigation

Navigation drawers

Up navigation

ResponsiveDesign

Why responsive

Responsive strategies

Fragments

Resource framework

Holo Visual Language

Dividers and borderless buttons

List headings

Typography

Full-bleed images

Generating assets

Page 6: 115 - Android Design for UI Developers (1)

App Navigation

Page 7: 115 - Android Design for UI Developers (1)

Action bar tabsand spinner

7

Page 8: 115 - Android Design for UI Developers (1)

ActionBarCompat

8

Native API ActionBarCompat

Activity or FragmentActivity ActionBarActivity

getActionBar() getSupportActionBar()

Theme.Holo Widget.Holo...

Theme.AppCompat Widget.AppCompat...

android:actionBarStyle android:displayOptions

actionBarStyle (no prefix)displayOptions (no prefix)

android:showAsAction yourAppNamespace:showAsAction

Android 2.1+(99.9% of devices)

Alternatively, continue using Jake Wharton’s incredible ActionBarSherlock library

COMING SOON

Page 9: 115 - Android Design for UI Developers (1)

ViewPager

9

Page 10: 115 - Android Design for UI Developers (1)

Navigation drawers

Primarily for main app navigation

Only for 3+ top level views of disparate, mutually exclusive content

More at d.android.com/design

10

Page 11: 115 - Android Design for UI Developers (1)

Navigation drawers

11

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent">

<!-- The main content view --> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" />

<!-- The navigation drawer --> <ListView android:id="@+id/nav_drawer" android:layout_gravity="start" android:layout_width="@dimen/drawer_width" android:layout_height="match_parent" android:background="#ffCCCCCC"/>

</android.support.v4.widget.DrawerLayout>

Page 12: 115 - Android Design for UI Developers (1)

ActionBarDrawerToggleand DrawerListener

12

DRAWER CLOSED

DRAWER OPEN

// ActionBarDrawerToggle provides convenient helpers// for tying together the prescribed interactions// between a top-level sliding drawer and the action bar.mDrawerToggle = new ActionBarDrawerToggle( this, /* activity */ mDrawerLayout, R.drawable.ic_drawer, /* download available */ R.string.drawer_open, /* content descriptions */ R.string.drawer_close) {

public void onDrawerClosed(View view) { // Set the action bar title to the content title. getActionBar().setTitle(mTitle); }

public void onDrawerOpened(View drawerView) { getActionBar().setTitle(“Navigation Drawer Example”); }};mDrawerLayout.setDrawerListener(mDrawerToggle);

Page 13: 115 - Android Design for UI Developers (1)

ActionBarDrawerToggle

13

@Overridepublic boolean onOptionsItemSelected(MenuItem item) { /* * The action bar home/up action should open or * close the drawer. * ActionBarDrawerToggle will take care of this. */ if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } return super.onOptionsItemSelected(item);}

DRAWER CLOSED

DRAWER OPEN

Page 14: 115 - Android Design for UI Developers (1)

Up navigation

14

<activity android:name=".MyChildActivity" android:parentActivityName=".MyParentActivity">

<meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".MyParentActivity" />

</activity>

<style name="ActionBar" parent="android:Widget.Holo.ActionBar"> <item name="android:displayOptions">showHome|homeAsUp|showTitle</item></style>

Page 15: 115 - Android Design for UI Developers (1)

Custom Up navigation

15

@Overridepublic Intent getParentActivityIntent() { // Used when navigating within the same task. return new Intent(this, MyParentActivity.class) .putExtra(START_TAB, 2);}

@Overridepublic void onCreateNavigateUpTaskStack(TaskStackBuilder builder) { // Used when synthesizing the stack in a new task. builder.addNextIntent(new Intent(this, HomeActivity.class)) .addNextIntent(getParentActivityIntent());}

Page 16: 115 - Android Design for UI Developers (1)

Responsive Design

Page 17: 115 - Android Design for UI Developers (1)

Device variety

17

Page 18: 115 - Android Design for UI Developers (1)

Why responsive?

18

Page 19: 115 - Android Design for UI Developers (1)

Why responsive?

19

android:layout_width="match_parent"

WARNING

Page 20: 115 - Android Design for UI Developers (1)

Why responsive?

Page 21: 115 - Android Design for UI Developers (1)

Why responsive?

21

Page 22: 115 - Android Design for UI Developers (1)

Combination

22

Page 23: 115 - Android Design for UI Developers (1)

Fragments

23

A B A B

Page 24: 115 - Android Design for UI Developers (1)

Alternate layouts

24

<LinearLayout …> <fragment android:name="com.example.ListFragment" /></LinearLayout>

res/layout/activity_home.xml

<LinearLayout …> <fragment android:name="com.example.DetailFragment" /></LinearLayout>

res/layout/activity_detail.xml

Page 25: 115 - Android Design for UI Developers (1)

Alternate layouts

25

<LinearLayout …> <fragment android:name= "com.example.ListFragment" /> <fragment android:name= "com.example.DetailFragment" /></LinearLayout>

res/layout-w600dp/activity_home.xml

Page 26: 115 - Android Design for UI Developers (1)

Master/Detail Flow template

26

File > New > Android Object

Page 27: 115 - Android Design for UI Developers (1)

SlidingPaneLayout

27

Page 28: 115 - Android Design for UI Developers (1)

SlidingPaneLayout

28

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sliding_pane" android:layout_width="match_parent" android:layout_height="match_parent">

<!-- First child is the left pane --> <fragment android:name="com.example.ListFragment" android:id="@+id/left_pane" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="start" />

<!-- Second child is the right (content) pane --> <fragment android:name="com.example.DetailFragment" android:id="@+id/content_pane" android:layout_width="600dp" android:layout_weight="1" android:layout_height="match_parent" />

</android.support.v4.widget.SlidingPaneLayout>

Page 29: 115 - Android Design for UI Developers (1)

29

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sliding_pane" android:layout_width="match_parent" android:layout_height="match_parent">

<!-- First child is the left pane --> <fragment android:name="com.example.ListFragment" android:id="@+id/left_pane" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="start" />

<!-- Second child is the right (content) pane --> <fragment android:name="com.example.DetailFragment" android:id="@+id/content_pane" android:layout_width="600dp" android:layout_weight="1" android:layout_height="match_parent" />

</android.support.v4.widget.SlidingPaneLayout>

If combined pane widths exceed screen width then

right pane overlaps

SlidingPaneLayout

Page 30: 115 - Android Design for UI Developers (1)

30

<android.support.v4.widget.SlidingPaneLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/sliding_pane" android:layout_width="match_parent" android:layout_height="match_parent">

<!-- First child is the left pane --> <fragment android:name="com.example.ListFragment" android:id="@+id/left_pane" android:layout_width="280dp" android:layout_height="match_parent" android:layout_gravity="start" />

<!-- Second child is the right (content) pane --> <fragment android:name="com.example.DetailFragment" android:id="@+id/content_pane" android:layout_width="600dp" android:layout_weight="1" android:layout_height="match_parent" />

</android.support.v4.widget.SlidingPaneLayout>

Grow to consume available space

SlidingPaneLayout

Page 31: 115 - Android Design for UI Developers (1)

Macro reflow

31

Page 32: 115 - Android Design for UI Developers (1)

32

<LinearLayoutxmlns:android="…"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent">

<fragment … />

<fragment … />

</LinearLayout>

res/layout/activity_home.xml

<LinearLayoutxmlns:android="…"android:orientation="horizontal"android:baselineAligned="false"android:layout_width="match_parent"android:layout_height="match_parent">

<fragment … />

<fragment … />

</LinearLayout>

res/layout-land/activity_home.xml

Alternate layouts

Page 33: 115 - Android Design for UI Developers (1)

Micro reflow

33

Page 34: 115 - Android Design for UI Developers (1)

Dimension files

34

headline_text_size

body_text_size

page_margin

body_line_spacing

<resources> … <dimen name="page_margin">32dp</dimen> <dimen name="body_text_size">22sp</dimen> …</resources>

res/values-sw720dp/dimens.xml

res/values/dimens.xml

<resources> … <dimen name="page_margin">16dp</dimen> <dimen name="body_text_size">18sp</dimen> …</resources>

Page 35: 115 - Android Design for UI Developers (1)

Dimension files

35

headline_text_size

body_text_size

page_margin

body_line_spacing

res/values/dimens.xml

<resources> … <dimen name="page_margin">32dp</dimen> <dimen name="body_text_size">22sp</dimen> …</resources>

res/values-sw720dp/dimens.xml

<resources> … <dimen name="page_margin">16dp</dimen> <dimen name="body_text_size">18sp</dimen> …</resources>

Page 36: 115 - Android Design for UI Developers (1)

Margin point

36

Page 37: 115 - Android Design for UI Developers (1)

37

Margin point

<FrameLayout xmlns:android="…" android:layout_width="match_parent" android:layout_height="match_parent"> <ScrollView style="@style/MarginPoint" android:layout_height="match_parent" android:scrollbarStyle="outsideOverlay">

res/layout/activity_home.xml

<style name="MarginPoint"> <item name="android:layout_width">match_parent</item></style>

res/values/styles.xml

<style name="MarginPoint"> <item name="android:layout_width">600dp</item> <item name="android:layout_gravity">center_horizontal</item></style>

res/values-w600dp/styles.xml

Page 38: 115 - Android Design for UI Developers (1)

Lists to grids

38

Page 39: 115 - Android Design for UI Developers (1)

Lists to grids

39

<GridView … android:numColumns="@integer/num_columns" />

res/layout/activity_home.xml

<resources> <integer name="num_columns">1</integer></resources>

res/values/integers.xml

<resources> <integer name="num_columns">2</integer></resources>

res/values-w500dp/integers.xml

Page 40: 115 - Android Design for UI Developers (1)

Lists to grids

40

if (convertView == null) {int numColumns = getResources().getInteger(R.integer.num_columns);if (numColumns == 1) {

convertView = inflater.inflate(R.layout.list_item_layout, parent, false);

} else {convertView = inflater.inflate(R.layout.grid_item_layout, parent, false);

}}

MyAdapter#getView

Page 41: 115 - Android Design for UI Developers (1)

Responsive design

41

Page 42: 115 - Android Design for UI Developers (1)

Holo Visual Language

Page 43: 115 - Android Design for UI Developers (1)

Style Hierarchy

43

<style name="Theme.Base" parent="Theme.Light" />

<style name="Theme.MyTheme" parent="Theme.Base" />

res/values/styles.xml

<style name="Theme.Base" parent="Theme.Holo.Light" />

res/values-v11/styles.xml

Page 44: 115 - Android Design for UI Developers (1)

Style Hierarchy

44

<style name="Theme.Base" parent="Theme.Light" />

<style name="Theme.MyTheme" parent="Theme.Base" />

res/values/styles.xml

<style name="Theme.Base" parent="Theme.Holo.Light" />

res/values-v11/styles.xml

<style name="Theme.MyTheme" parent="Theme.AppCompat.Light" />

res/values/styles.xml COMING SOON

Page 45: 115 - Android Design for UI Developers (1)

Built-in framework resourcesJava: android.R.attr.foo

XML: ?android:foo or ?android:attr/foo

45

?android:progressBarStyleLarge

?android:borderlessButtonStyle

?android:listSeparatorTextViewStyle

?android:textAppearanceListItemSmall

Example style resources:

?android:actionBarSize

?android:listPreferredItemHeight(Small)

?android:listPreferredItemPaddingLeft

Example dimension resources:

?android:listChoiceIndicatorSingle

?android:dividerHorizontal

?android:selectableItemBackground

?android:textSelectHandleLeft

Example drawable resources:

Page 46: 115 - Android Design for UI Developers (1)

46

Page 47: 115 - Android Design for UI Developers (1)

Dividers

47

<LinearLayout android:orientation="vertical" ... android:showDividers="middle" android:divider="?android:dividerHorizontal">

Dividers and spacing (e.g. margins) establish hierarchy

Page 48: 115 - Android Design for UI Developers (1)

Dividers

48

<LinearLayout android:orientation="horizontal" ... android:showDividers="middle" android:divider="?android:dividerVertical" android:dividerPadding="8dp" android:baselineAligned="false">

Page 49: 115 - Android Design for UI Developers (1)

Borderless buttons

49

<ImageButton style="?android:borderlessButtonStyle" android:layout_width="48dp" android:layout_height="match_parent" android:src="@drawable/ic_action_delete" android:contentDescription="@string/delete" />

Page 50: 115 - Android Design for UI Developers (1)

50

Button bars

Button bar style automatically adds dividers between buttons

<LinearLayout style="?android:buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content">

Remember, preferred action on the right!

Page 51: 115 - Android Design for UI Developers (1)

Button bars

51

<Button style="?android:buttonBarButtonStyle" android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" android:text="@string/save" />

Page 52: 115 - Android Design for UI Developers (1)

Touch feedback

52

<FrameLayout android:layout_width="match_parent" android:layout_height="200dp" android:clickable="true" android:focusable="true" android:foreground="?android:selectableItemBackground" android:contentDescription="Item title here"> ...

Or android:background on any view type

android:listSelector for lists and grids

Page 53: 115 - Android Design for UI Developers (1)

List headings

53

<TextView style="?android:listSeparatorTextViewStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="List heading" />

2dp separator

14sp, bold, ALL CAPS(same as action bar tabs and

action bar item titles)

Page 54: 115 - Android Design for UI Developers (1)

Sophisticated typography with TextView

54

android:fontFamily="sans-serif-thin"

android:fontFamily="sans-serif-light"

android:fontFamily="sans-serif-condensed"

Download standard, condensed, and slab at

Google Fonts

(default)

Page 55: 115 - Android Design for UI Developers (1)

Full-bleed images with consistent aspect ratios

55

1dp separator<ImageView android:scaleType="centerCrop" android:src="@drawable/p1" android:layout_width="match_parent" android:layout_height="match_parent" />

centerCrop:

Page 58: 115 - Android Design for UI Developers (1)

GeneratingHolo assets

58

Android Asset StudioANDROID-UI-UTILS.GOOGLECODE.COM

Action Bar Style GeneratorACTIONBARSTYLEGENERATOR.COM

Android Holo ColorsANDROID-HOLO-COLORS.COM

Jeff and Jérôme are in the Developer

Sandbox!

Page 59: 115 - Android Design for UI Developers (1)

Thank You!

+Roman Nurik+Nick Butcher

Page 60: 115 - Android Design for UI Developers (1)

Developers