0
0
Android Kotlinmobile~10 mins

Box layout in Android Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a vertical LinearLayout container.

Android Kotlin
val layout = LinearLayout(this).apply {
  orientation = [1]
}
Drag options to blanks, or click blank then click option'
ALinearLayout.VERTICAL
BLinearLayout.HORIZONTAL
CLinearLayout.CENTER
DLinearLayout.WRAP_CONTENT
Attempts:
3 left
💡 Hint
Common Mistakes
Using HORIZONTAL instead of VERTICAL causes horizontal layout.
Using CENTER or WRAP_CONTENT is invalid for orientation.
2fill in blank
medium

Complete the code to add a TextView inside the Box layout with match_parent width.

Android Kotlin
val textView = TextView(this).apply {
  layoutParams = LinearLayout.LayoutParams([1], LinearLayout.LayoutParams.WRAP_CONTENT)
  text = "Hello Box"
}
Drag options to blanks, or click blank then click option'
ALinearLayout.LayoutParams.WRAP_CONTENT
BLinearLayout.LayoutParams.FILL_PARENT
CLinearLayout.LayoutParams.MATCH_PARENT
DLinearLayout.LayoutParams.WRAP_CONTENT + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using WRAP_CONTENT makes the TextView only as wide as its content.
FILL_PARENT is deprecated and should not be used.
3fill in blank
hard

Fix the error in setting the background color of the Box layout.

Android Kotlin
layout.setBackgroundColor([1].parseColor("#FF0000"))
Drag options to blanks, or click blank then click option'
AColorUtils
BColors
Ccolor
DColor
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or plural forms like colors causes errors.
Using ColorUtils does not have parseColor method.
4fill in blank
hard

Fill both blanks to create a Box layout with padding and gravity centered.

Android Kotlin
layout.apply {
  setPadding([1], [1], [1], [1])
  gravity = [2]
}
Drag options to blanks, or click blank then click option'
A16
BGravity.CENTER
CGravity.LEFT
D8
Attempts:
3 left
💡 Hint
Common Mistakes
Using Gravity.LEFT aligns children to the left, not center.
Using 8 for padding is smaller than typical spacing.
5fill in blank
hard

Fill all three blanks to create a Box layout with horizontal orientation, weight sum, and a weighted child.

Android Kotlin
val layout = LinearLayout(this).apply {
  orientation = [1]
  weightSum = [2]f
}
val child = View(this).apply {
  layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, [3]f)
}
Drag options to blanks, or click blank then click option'
ALinearLayout.VERTICAL
B1.0
C0.5
DLinearLayout.HORIZONTAL
Attempts:
3 left
💡 Hint
Common Mistakes
Using VERTICAL orientation but expecting horizontal layout.
Setting weightSum to 0 or missing f suffix causes errors.