[Android Kotlin 기초] 2-1. Anatomy of Basic Android Project

1: Anatomy of Basic Android Project

Created: Apr 1, 2021 12:03 PM link: https://developer.android.com/codelabs/kotlin-android-training-app-anatomy?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fkotlin-fundamentals-two%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fkotlin-android-training-app-anatomy#0

Activities

Views

View attributes

Strings

Using view

val rollButton: Button = findViewById(R.id.roll_button)
rollButton.setOnClickListener { rollDice() }

Question 1

Which method on an Activity inflates the app’s layout and makes its views available as objects?

In onCreate(), you specify which layout is associated with the activity, and you inflate the layout. The setContentView() method does both those things.

override fun onCreate(savedInstanceState: Bundle?) {   
	super.onCreate(savedInstanceState)   
	setContentView(R.layout.activity_main)
}

Question 2

Which view attribute do you use to set the width of a view so that it adjusts to fit the content?