Externalizing Resources:
Why is it a good practice?
Externalizing Resources:
Overview of how Android handles external resources
‘res’ folder
Overview
Resource filename requirements
Resource filenames should only contain:
List of Resource Types
and associated Subfolders in ‘res’
Resource Types:
Simple Values
Resource Types:
Simple Values:
Strings
Should be specified in res/values/strings.xml
Resource Types:
Simple Values:
Strings:
Using Formatted Strings
Resource Types:
Simple Values:
Strings:
Alternative Plural Forms
Allows you to specify an alternative form for any of: ‘zero’, ‘one’, ‘multiple’, ‘few’, ‘many’ or ‘other’ quantities.
<plurals></plurals>
<item>One Goose</item>
<item>%d Geese</item>
String geeseStr = resources.getQuantityString(R.plurals.goose_count, gCount, gCount);
Resource Types:
Values:
Colors
Defined in res/values/colors.xml
Resource Types:
Values:
Dimensions
Dimensions are commonly referenced within style and layout resources.
Useful for defining layout values such as borders and heights.
Resource Types:
Values:
Dimensions:
Scales
Scales:
Resource Types:
Values:
Dimensions:
Best Practices
It is best practice to use either Density Independent or Scalable pixels.
These let you define a dimension using relative scales that account for different screen resolutions and densities, simplifying scaling on different hardware.
Scalable pixels are particularly good for defining font sizes. They automatically scale if the user changes the system font size.
Resource Types:
Values:
Styles
Styles let an app maintain a consistent look and feel.
Specifies the attribute values used by Views:
Most commonly colors, borders and font sizes.
<style></style>
<item>14sp</item>
<item>#111</item>
Resource Types:
Drawables
Stored as individual files in the res/drawable folder
Basic Files:
Complex Composite Files:
The preferred format for Drawable bitmap resources is PNG, but JPG and GIF are also supported
Resource Types:
MipMaps
res/mipmap
Resource Types:
Layouts
Layout resources enable you to decouple the Presentation Layer from Business Logic.
UI Layouts are designed in XML.
Stored in res/layout
Animations:
3 Kinds
Animations:
Property Animations
Overview
A “tweened”(interpolated) animation that applies incremental changes when changing some property on an object.
Animations:
View Animations
Overview
“Tweened” animations that can be applied to rotate, move, fade and stretch a View
Animations:
Frame-by-Frame Animations
Overview
Represent a sequence of Drawables, each displayed for a specified duration.
Using Resources:
Basic Topics
Using Resources in Code:
The R class
R
Using Resources in Code:
Resource class
The Resource class represents the resource table within the application.