Supporting Multiple Android Device Definitions

Supporting Multiple
Android Device Definitions
Chiu-Ki Chan
@chiuki
bit.ly/muland
@chiuki@chiuki
So many devices!
@chiuki@chiuki
Infinite screen sizes!
@chiuki@chiuki
Responsive
+
Progressive
Hello World
@chiuki
@chiuki
@chiuki
@chiuki
@chiuki
@chiuki
@chiuki
Declarative Layout
@chiuki
@chiuki
@chiuki
(x,y)
@chiuki
(x,y)
@chiuki
Center
@chiuki@chiuki
Center
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/start" />
@chiuki
@chiuki@chiuki
Proportional Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<ImageView
android:id="@+id/image2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
@chiuki
@chiuki
Divider
@chiuki@chiuki
Divider
<LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
@chiuki@chiuki
Divider
<LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/black" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
@chiuki
dp
@chiuki
dpDensity-independent pixel
@chiuki
@chiuki
@chiuki@chiuki
res/layout-land
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/image2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
@chiuki
Resource Folders
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
res/layout-land/activity_main.xml
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
res/drawable-hdpi/ic_launcher.png
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
res/drawable-large-land/splash.png
@chiuki
res/drawable-large-land/splash.png
@chiuki
res/drawable/splash.xml
@chiuki
res/drawable/splash.xml
XML drawable
@chiuki@chiuki
XML shape
<shape android:shape="rectangle" >
<gradient
android:startColor="#063"
android:endColor="#030"
android:angle="270" />
</shape>
@chiuki@chiuki
Gradient
@chiuki@chiuki
Gradient
@chiuki@chiuki
Pattern
@chiuki@chiuki
Tiles
@chiuki@chiuki
Tiles
@chiuki@chiuki
Tiling background
<bitmap
android:src="@drawable/tile"
android:tileMode="repeat"
android:dither="true" />
res/drawable/background.xml
@chiuki@chiuki
<bitmap
android:src="@drawable/tile"
android:tileMode="repeat"
android:dither="true" />
res/drawable/background.xml
tile.png
Tiling background
@chiuki@chiuki
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background" />
res/layout/activity_main.xml
res/drawable/background.xml
Tiling background
@chiuki@chiuki
Tile mode
clamp
Replicates the edge color
repeat
Repeats the bitmap in both direction
mirror
Repeats with alternating mirror images
@chiuki@chiuki
GridView
@chiuki@chiuki
Auto fit columns
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="@dimen/workbook_column_width"
android:padding="@dimen/workbook_padding"
android:horizontalSpacing="@dimen/workbook_spacing"
android:verticalSpacing="@dimen/workbook_spacing"
android:scrollbarStyle="outsideOverlay" />
@chiuki@chiuki
Auto fit columns
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="@dimen/workbook_column_width"
android:padding="@dimen/workbook_padding"
android:horizontalSpacing="@dimen/workbook_spacing"
android:verticalSpacing="@dimen/workbook_spacing"
android:scrollbarStyle="outsideOverlay" />
@chiuki@chiuki
Auto fit columns
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="auto_fit"
android:columnWidth="@dimen/workbook_column_width"
android:padding="@dimen/workbook_padding"
android:horizontalSpacing="@dimen/workbook_spacing"
android:verticalSpacing="@dimen/workbook_spacing"
android:scrollbarStyle="outsideOverlay" />
@chiuki@chiuki
<resources>
<dimen name="workbook_padding">8dp</dimen>
<dimen name="workbook_spacing">12dp</dimen>
<dimen name="workbook_column_width">120dp</dimen>
<resources>
res/values/dimens.xml
values/dimen.xml
@chiuki@chiuki
values-large/dimen.xml
<resources>
<dimen name="workbook_padding">32dp</dimen>
<dimen name="workbook_spacing">18dp</dimen>
<dimen name="workbook_column_width">180dp</dimen>
<resources>
res/values-large/dimens.xml
@chiuki@chiuki
7-inch
@chiuki@chiuki
Phone
@chiuki@chiuki
Fragments
github.com/codepath/android-master-detail-demo
Progressive
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
@chiuki@chiuki
Resource Folders
Type Variation
layout
values
drawable
menu
Language & Region: en, fr, fr-rCA
Screen size: small, large, xlarge, sw320dp, h720dp
Screen orientation: port, land
Screen density: ldpi, mdpi, hdpi, xhdpi, nodpi, tvdpi
Platform version: v4, v11, v14, v21
UI mode: car, desk, television, appliance
http://developer.android.com/guide/topics/resources/providing-resources.html
@chiuki@chiuki
Ripples
@chiuki@chiuki
Ripples
@chiuki@chiuki
drawable-v21
<ripple android:color="@color/colorAccent">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
</ripple>
res/drawable-v21/background.xml
@chiuki@chiuki
drawable as default
<selector>
<item android:state_pressed="true"
android:drawable="@color/colorAccent" />
<item android:drawable="@color/colorPrimary" />
</selector>
res/drawable/background.xml
@chiuki@chiuki
android:background
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="drawable/background"
android:text="@string/click_me" />
@chiuki@chiuki
Progressive
@chiuki@chiuki
API level
@chiuki@chiuki
Detect API level
android.os.Build.VERSION.SDK_INT
@chiuki@chiuki
// Default value
int heapSize = 16;
// Detect OS version
int sdk = Integer.parseInt(Build.VERSION.SDK_INT);
// Progressive enhancement for newer devices
if (sdk >= Build.VERSION_CODES_ECLAIR) {
heapSize = getHeapSize(this);
}
Progressive
@chiuki@chiuki
getHeapSize
public int getHeapSize() {
ActivityManager activityManager = (ActivityManager)
getSystemService(Context.ACTIVITY_SERVICE);
return activityManager.getMemoryClass();
}
@chiuki@chiuki
Ship new functionality with your app!
Support Library
@chiuki
Support Library
Fragment
TaskStackBuilder
LruCache
ViewPager
DrawerLayout
SlidingPaneLayout
Loader
AppCompat
VectorDrawable
RecyclerView
@chiuki
AppCompat
Material Design
@chiuki
Support library only
RecyclerView
Summary
@chiuki@chiuki
Summary
Responsive layout
Declarative layout
Density-independent pixels (dp)
Resource folders
XML drawables
Progressive functionality
Resource folders
Version check
Support library
Slides
bit.ly/muland
@chiuki@chiuki
Thank you!
Learn more
developer.android.com/training/multiscreen
is.gd/FluidAndroidLayouts
is.gd/BeautifulAndroid
pluralsight.com/authors/chiuki-chan
Stay in touch
tinyletter.com/sqisland
blog.sqisland.com
twitter.com/chiuki
Slides
bit.ly/muland
@chiuki@chiuki
@chiuki@chiuki
360|AnDev Core Track
• Activities in the Wild: Exploring the Activity
Lifecycle
• Fragments: What are they good for
• Async Task, Threads, Pools and Executors
• Measure, Layout, Draw, Repeat: Custom Views
and ViewGroups
• A Practical Guide to Material Design
implementation for Android Developers
• Libraries I wish I knew about when I started
• Intro to iOS for Android developers
@chiuki@chiuki
Discount Code:
DroidCommunity
1 of 82

Recommended

Bust the Android Fragmentation Myth by
Bust the Android Fragmentation MythBust the Android Fragmentation Myth
Bust the Android Fragmentation MythChiu-Ki Chan
24.4K views76 slides
[@NaukriEngineering] Icon fonts & vector drawable in iOS apps by
[@NaukriEngineering] Icon fonts & vector drawable in iOS apps[@NaukriEngineering] Icon fonts & vector drawable in iOS apps
[@NaukriEngineering] Icon fonts & vector drawable in iOS appsNaukri.com
855 views14 slides
[@NaukriEngineering] Apache Spark by
[@NaukriEngineering] Apache Spark[@NaukriEngineering] Apache Spark
[@NaukriEngineering] Apache SparkNaukri.com
448 views29 slides
What's new in Android Lollipop by
What's new in Android LollipopWhat's new in Android Lollipop
What's new in Android LollipopAbdellah SELASSI
1.9K views59 slides
Android - What's new? by
Android -  What's new? Android -  What's new?
Android - What's new? Moyinoluwa Adeyemi
846 views26 slides
Android Development by
Android DevelopmentAndroid Development
Android DevelopmentPluu love
543 views47 slides

More Related Content

More from Chiu-Ki Chan

Yes, you can draw with your engineering brain by
Yes, you can draw with your engineering brainYes, you can draw with your engineering brain
Yes, you can draw with your engineering brainChiu-Ki Chan
172 views43 slides
How to be an Android Expert: Women Who Code Connect by
How to be an Android Expert: Women Who Code ConnectHow to be an Android Expert: Women Who Code Connect
How to be an Android Expert: Women Who Code ConnectChiu-Ki Chan
1.3K views104 slides
how-to-be-an-android-expert-wwcode by
how-to-be-an-android-expert-wwcodehow-to-be-an-android-expert-wwcode
how-to-be-an-android-expert-wwcodeChiu-Ki Chan
227 views104 slides
How to be an Android Expert: Droidcon Berlin by
How to be an Android Expert: Droidcon BerlinHow to be an Android Expert: Droidcon Berlin
How to be an Android Expert: Droidcon BerlinChiu-Ki Chan
2.3K views75 slides
How to be an Android Expert: Droidcon Boston by
How to be an Android Expert: Droidcon BostonHow to be an Android Expert: Droidcon Boston
How to be an Android Expert: Droidcon BostonChiu-Ki Chan
3.2K views113 slides
How to Write a Conference Proposal by
How to Write a Conference ProposalHow to Write a Conference Proposal
How to Write a Conference ProposalChiu-Ki Chan
2.3K views27 slides

More from Chiu-Ki Chan(12)

Yes, you can draw with your engineering brain by Chiu-Ki Chan
Yes, you can draw with your engineering brainYes, you can draw with your engineering brain
Yes, you can draw with your engineering brain
Chiu-Ki Chan172 views
How to be an Android Expert: Women Who Code Connect by Chiu-Ki Chan
How to be an Android Expert: Women Who Code ConnectHow to be an Android Expert: Women Who Code Connect
How to be an Android Expert: Women Who Code Connect
Chiu-Ki Chan1.3K views
how-to-be-an-android-expert-wwcode by Chiu-Ki Chan
how-to-be-an-android-expert-wwcodehow-to-be-an-android-expert-wwcode
how-to-be-an-android-expert-wwcode
Chiu-Ki Chan227 views
How to be an Android Expert: Droidcon Berlin by Chiu-Ki Chan
How to be an Android Expert: Droidcon BerlinHow to be an Android Expert: Droidcon Berlin
How to be an Android Expert: Droidcon Berlin
Chiu-Ki Chan2.3K views
How to be an Android Expert: Droidcon Boston by Chiu-Ki Chan
How to be an Android Expert: Droidcon BostonHow to be an Android Expert: Droidcon Boston
How to be an Android Expert: Droidcon Boston
Chiu-Ki Chan3.2K views
How to Write a Conference Proposal by Chiu-Ki Chan
How to Write a Conference ProposalHow to Write a Conference Proposal
How to Write a Conference Proposal
Chiu-Ki Chan2.3K views
How to be an Android Expert: Android Summit by Chiu-Ki Chan
How to be an Android Expert: Android SummitHow to be an Android Expert: Android Summit
How to be an Android Expert: Android Summit
Chiu-Ki Chan15.8K views
Intro to Android for iOS developers by Chiu-Ki Chan
Intro to Android for iOS developersIntro to Android for iOS developers
Intro to Android for iOS developers
Chiu-Ki Chan8.6K views
Hands-on Icon creation by Chiu-Ki Chan
Hands-on Icon creationHands-on Icon creation
Hands-on Icon creation
Chiu-Ki Chan1.5K views
Develop your voice by Chiu-Ki Chan
Develop your voiceDevelop your voice
Develop your voice
Chiu-Ki Chan2.1K views
How to win hackathons, Ignite Google I/O 2012 by Chiu-Ki Chan
How to win hackathons, Ignite Google I/O 2012How to win hackathons, Ignite Google I/O 2012
How to win hackathons, Ignite Google I/O 2012
Chiu-Ki Chan1.6K views
I have nothing to say, Ignite Where 2012 by Chiu-Ki Chan
I have nothing to say, Ignite Where 2012I have nothing to say, Ignite Where 2012
I have nothing to say, Ignite Where 2012
Chiu-Ki Chan2.2K views

Recently uploaded

Attacking IoT Devices from a Web Perspective - Linux Day by
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day Simone Onofri
16 views68 slides
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
31 views35 slides
STPI OctaNE CoE Brochure.pdf by
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdfmadhurjyapb
14 views1 slide
Piloting & Scaling Successfully With Microsoft Viva by
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft VivaRichard Harbridge
12 views160 slides
Unit 1_Lecture 2_Physical Design of IoT.pdf by
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdfStephenTec
12 views36 slides
Transcript: The Details of Description Techniques tips and tangents on altern... by
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...BookNet Canada
136 views15 slides

Recently uploaded(20)

Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Piloting & Scaling Successfully With Microsoft Viva by Richard Harbridge
Piloting & Scaling Successfully With Microsoft VivaPiloting & Scaling Successfully With Microsoft Viva
Piloting & Scaling Successfully With Microsoft Viva
Unit 1_Lecture 2_Physical Design of IoT.pdf by StephenTec
Unit 1_Lecture 2_Physical Design of IoT.pdfUnit 1_Lecture 2_Physical Design of IoT.pdf
Unit 1_Lecture 2_Physical Design of IoT.pdf
StephenTec12 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada127 views
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ... by Jasper Oosterveld
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
ESPC 2023 - Protect and Govern your Sensitive Data with Microsoft Purview in ...
SAP Automation Using Bar Code and FIORI.pdf by Virendra Rai, PMP
SAP Automation Using Bar Code and FIORI.pdfSAP Automation Using Bar Code and FIORI.pdf
SAP Automation Using Bar Code and FIORI.pdf
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
AMAZON PRODUCT RESEARCH.pdf by JerikkLaureta
AMAZON PRODUCT RESEARCH.pdfAMAZON PRODUCT RESEARCH.pdf
AMAZON PRODUCT RESEARCH.pdf
JerikkLaureta26 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi127 views

Supporting Multiple Android Device Definitions