Lesson 4 Build Your First Android App
Lesson 4 Build Your First Android App
14
18
<TextView
Hello World!
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
● wrap_content
android:layout_width="wrap_content"
● match_parent
android:layout_width="match_parent"
● Fixed value (use dp units)
android:layout_width="48dp"
The ViewGroup is the parent and the views inside it are its children.
android:layout_height="match_parent">
<TextView TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"/>
</FrameLayout>
<LinearLayout
TextView
android:layout_width="match_parent"
TextView
android:layout_height="match_parent"
android:orientation="vertical">
Button
<TextView ... />
<TextView ... />
<Button ... />
</LinearLayout>
LinearLay
out ImageView
Butto Butto
n n
Button Button
Within your app, you can now refer to this specific TextView using:
R.id.helloTextView
32
Activity
launched
onCreate()
App is running
Activity shut
down
Activity
ViewGrou
p
Layout files LayoutInflat
View1 ViewGrou
layout1 layout2 layout3 er
p
View2 View3
38
An event is
fired
val runnable
is equivalent to = Runnable { println("Hi there") }
val runnable = (object: Runnable {
override fun run() {
println("Hi there")
}
})
init {
// retrieve records given an id
}
}
47
● Declare plugins
● Define Android properties
● Handle dependencies
● Connect to repositories
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.sample"
minSdkVersion 19
targetSdkVersion 30
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-
jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
...
}
repositories {
google()
jcenter()
maven {
url "https://maven.example.com"
}
}
● Clean
● Tasks
● InstallDebug
55
57
● Content labels
● Touch target sizes
● Clickable views
● Text and image contrast
<ImageView
...
android:contentDescription="@string/stop_sign" />
Reads text
aloud as
user
navigates
the screen
69
● Layouts
● LinearLayout
● Input events overview
● View
● ViewGroup