83 lines
2.1 KiB
Markdown
83 lines
2.1 KiB
Markdown
# Activities
|
|
|
|
Subclasses of **android.app.Activity**
|
|
|
|
- Present a visual UI
|
|
- Each activity has its own 'window'
|
|
- Only one 'window' on screen at once
|
|
- **Granular management** of the resources of an application
|
|
- UI layout - a 'view'
|
|
- Specified in a separate XML file
|
|
- Constructed programmatically
|
|
- Apps usually have several activities
|
|
|
|
#### Android UI
|
|
|
|
An activity has a window associated with it - usually full screen.
|
|
|
|

|
|
|
|
#### View Hierarchy
|
|
|
|
There are 3 types of views:
|
|
|
|
1. Those that display something (`Views`)
|
|
2. Those that do something (`Widgets`)
|
|
3. Those that lay out sub-views (`ViewGroups`)
|
|
|
|
##### View Principles
|
|
|
|
Mobile devices are rarely the same, i.e. they have different screen sizes & resolutions
|
|
|
|
* Layout should **adapt** to the screen it is inflated in
|
|
* No hard-coding, layouts are defined in hierarchies and relationships.
|
|
* Different layouts for orientation
|
|
|
|
###### ViewGroups
|
|
|
|
* Frame Layout
|
|
* Simplest - contains a single object
|
|
* Linear Layout
|
|
* Aligns all children in a single direction
|
|
* Table Layout
|
|
* Positions children into columns and rows
|
|
* Constraint Layout
|
|
* Allows children to specify their position relative to their parent view
|
|
* Scroll View
|
|
* A vertical scrolling view; only contains a single element
|
|
|
|
###### Views Widgets
|
|
|
|
* Views that the user can optionally interact with
|
|
* Buttons, text view, calendar viewer, image viewer, etc.
|
|
* Generate UI events
|
|
|
|
###### Views Parameters
|
|
|
|
* width or height
|
|
* Use percentages - relative to parent or screen width, etc.
|
|
* ID
|
|
* Used to generate a Java member variable we can refer to within the program
|
|
* Basic binding of methods
|
|
* Used to automatically bind UI events to methods
|
|
|
|
###### Views Resources
|
|
|
|
* Layouts are an example of a *resource*
|
|
* Static content used by components at run-time
|
|
* Can be referenced by ID
|
|
|
|
Data Binding - involves a lot of boilerplate code
|
|
|
|
`@{}` notation - receives data changes
|
|
|
|
`@={}` - receives data changes to the property and listens to user updates
|
|
|
|
##### Model-View-ViewModel
|
|
|
|

|
|
|
|
## The Manifest
|
|
|
|
A *list* of the application's components
|