Modern Android UI with Jetpack Compose: Q&A and Code for Text, Image, Column & Card
Jetpack Compose has revolutionized Android UI development with a modern, declarative approach. Whether you’re preparing for interviews, brushing up on fundamentals, or building real-world apps, mastering components like Text, Image, Column, and Card is essential.
In this article, you’ll find 40+ questions and answers, structured by experience level — Beginner, Intermediate, and Advanced. Each section gives you the theory and the how-to for practical usage.
Let’s dive in.
Beginner Level – Laying the Foundation
If you're just starting out with Jetpack Compose, these questions will help you get comfortable with how to build basic layouts using Text, Image, Column, and Card.
Text
Text is the most basic composable — used to display string content with styling, color, and alignment.
-
Q: How do you display a simple text in Jetpack Compose?
A: UseText("Hello World"). -
Q: How do you change the font size of text?
A: UsefontSize = 20.sp. -
Q: How do you make the text bold?
A: UsefontWeight = FontWeight.Bold. -
Q: How do you center-align text?
A: UsetextAlign = TextAlign.Center. -
Q: How do you change the color of the text?
A: Usecolor = Color.Red. -
Q: How do you underline text?
A: UseTextStyle(textDecoration = TextDecoration.Underline). -
Q: Can the Text composable show emojis?
A: Yes, Compose supports emojis likeText("🚀 Compose!"). -
Q: How do you add padding to text?
A: UseModifier.padding(...). -
Q: Can text span multiple lines by default?
A: Yes, it wraps content automatically. -
Q: What import is needed for the Text composable?
A:import androidx.compose.material3.Text
Image
Images in Compose are drawn using the Image composable and can be styled or loaded dynamically.
-
Q: How do you display a local image in Jetpack Compose?
A: UseImage(painter = painterResource(id = R.drawable.image), contentDescription = null). -
Q: How do you resize an image?
A: UseModifier.size(100.dp). -
Q: How do you make an image circular?
A: UseModifier.clip(CircleShape). -
Q: What is contentDescription used for?
A: For accessibility support (screen readers). -
Q: How do you scale image content?
A: UsecontentScale = ContentScale.Crop. -
Q: Can you display an internet image with the default Image composable?
A: No, use libraries like Coil (AsyncImage). -
Q: How do you tint an image?
A: UsecolorFilter = ColorFilter.tint(Color.Blue). -
Q: How do you align an image inside a Column?
A: UseModifier.align(Alignment.CenterHorizontally). -
Q: How do you add a border to an image?
A: UseModifier.border(...). -
Q: What does painterResource do?
A: It loads drawable resources into a Painter.
Column
Column is a vertical layout that allows you to stack composables on top of each other.
-
Q: What is a Column in Compose?
A: A layout that stacks elements vertically. -
Q: How do you space items inside a Column?
A: UseverticalArrangement = Arrangement.spacedBy(...). -
Q: How do you center elements in a Column?
A: UsehorizontalAlignment = Alignment.CenterHorizontally. -
Q: How do you make a Column scrollable?
A: UseModifier.verticalScroll(rememberScrollState()). -
Q: How do you make a Column clickable?
A: UseModifier.clickable { ... }. -
Q: How do you add padding to a Column?
A: UseModifier.padding(...). -
Q: Can Columns be nested?
A: Yes. -
Q: What is the default alignment in Column?
A: Top and start aligned. -
Q: How do you align children to the end?
A: UsehorizontalAlignment = Alignment.End. -
Q: What import is needed for Column?
A:import androidx.compose.foundation.layout.Column
Card
Cards are used for containing grouped elements like text and images, usually with padding, elevation, and background color.
-
Q: How do you create a card in Compose?
A:Card { Text("Inside a Card") } -
Q: How do you round the corners of a card?
A: Useshape = RoundedCornerShape(...). -
Q: How do you add elevation to a card?
A: Useelevation = CardDefaults.cardElevation(...). -
Q: How do you set a background color in a card?
A: Usecolors = CardDefaults.cardColors(...). -
Q: How do you make a card clickable?
A: AddModifier.clickable { ... }. -
Q: Can a card hold both text and images?
A: Yes. -
Q: How do you add padding inside a card?
A: UseModifier.padding(...)inside the content. -
Q: Can cards be nested?
A: Yes. -
Q: How do you make a card fill the screen width?
A: UseModifier.fillMaxWidth(). -
Q: What import is needed for Card?
A:import androidx.compose.material3.Card
Advanced Level – Expert Mastery
This final section is designed for developers preparing for senior-level Android interviews or aiming to build complex Compose UIs. You’ll tackle use cases involving animations, gestures, scroll optimizations, dynamic shapes, and more.
Image (Advanced)
-
Q: How do you create a crossfade transition between images?
A: Use Coil’sAsyncImage()withcontentScale = ContentScale.CropandfadeIn = true. -
Q: How do you crop an image to a dynamic custom shape?
A: UseModifier.clip(CustomShape)whereCustomShapeimplements theShapeinterface. -
Q: How do you apply a custom shadow or elevation effect to an image?
A: UseModifier.shadow(...)ordrawBehindto add custom drop shadows. -
Q: How do you apply a color matrix or shader effect to an image?
A: UsegraphicsLayerandRenderEffect.createColorFilterEffect(...)(Android 12+). -
Q: How do you gracefully handle image loading errors from the network?
A: Use Coil’serror = painterResource(...)and show fallback UI via conditionals. -
Q: How do you blur an image in Jetpack Compose?
A: UseModifier.blur(radius)(requires Android 12+ or Compose 1.3+). -
Q: How do you preload a set of images for future use?
A: Use Coil’sImageLoader.enqueue(request)in a coroutine. -
Q: How do you animate scale or opacity of an image on user interaction?
A: UseModifier.pointerInput { ... }and control animation withAnimatableoranimateFloatAsState. -
Q: How do you tint part of an image selectively?
A: Use a customPainteror overlay a shape with partial alpha on top. -
Q: How do you provide theme-aware image resources (light vs dark mode)?
A: UseisSystemInDarkTheme()and conditionally load different images.
Column (Advanced)
-
Q: How do you build a LazyColumn from dynamic API data?
A: Collect the data into aState(e.g., from ViewModel) and pass it intoLazyColumn { items(dataList) { ... } }. -
Q: How do you animate item reordering in a LazyColumn?
A: ApplyModifier.animateItemPlacement()to each item and update the backing list with reorder logic. -
Q: How do you preserve and restore scroll position across navigation or rotation?
A: UserememberSaveable { LazyListState() }and restore it when navigating back. -
Q: How do you implement drag-and-drop reordering in a column?
A: Use a library like Accompanist Reorderable or create a custom pointerInput-based solution. -
Q: How do you add sticky headers and dynamic content in a LazyColumn?
A: UsestickyHeader { ... }anditems(...)blocks for flexible layouts. -
Q: How do you combine static and dynamic elements in one LazyColumn?
A: Useitem { StaticUI() }followed byitems(data) { ... }. -
Q: How do you detect scroll direction in a performant way?
A: UseLazyListStateand track thefirstVisibleItemIndexandfirstVisibleItemScrollOffset. -
Q: How do you group items under section headers in a LazyColumn?
A: Use a data model with group headers, then useitemsIndexedandifconditions to insert headers. -
Q: How do you compose deeply nested item views without performance issues?
A: Usekeyinitems()and memoize heavy components. -
Q: How do you disable scrolling in a LazyColumn conditionally?
A: Avoid attaching a scroll state or useuserScrollEnabled = false.
Card (Advanced)
-
Q: How do you create a swipeable Tinder-style card?
A: UseModifier.pointerInput(...)to track drag gestures and animate translation usingAnimatable. -
Q: How do you handle state restoration inside a card (e.g., toggle states)?
A: UserememberSaveableand manage state at the card level. -
Q: How do you dynamically animate a card's shape on interaction?
A: Change theshapeusing state and animate withanimateDpAsState()oranimateShapeAsState(). -
Q: How do you embed advanced layouts like ConstraintLayout inside a Card?
A: Simply placeConstraintLayout { ... }inside theCard’s content block. -
Q: How do you animate a card's size during expansion or collapse?
A: UseModifier.animateContentSize()for automatic layout transitions. -
Q: How do you track when a card becomes visible on screen in a list?
A: UseLazyListState.layoutInfo.visibleItemsInfoand check if the card's index is present. -
Q: How do you debounce rapid taps on a card?
A: Use aCoroutineScopewith delay logic or debounce extensions. -
Q: How do you group cards into a paginated view?
A: UseHorizontalPager()from the Accompanist library. -
Q: How do you apply a vertical gradient background to a Card?
A: UseModifier.background(Brush.verticalGradient(...)). -
Q: How do you test card content and behavior using Jetpack Compose testing APIs?
A: UseModifier.testTag("card")and assert withcomposeTestRule.onNodeWithTag(...).assertExists().
Jetpack Compose Interview Q&A with Code Examples
Beginner Level
Text
Q: How do you display styled text in Jetpack Compose?
@Composable
fun StyledText() {
Text(
text = "Hello, Jetpack Compose!",
fontSize = 20.sp,
fontWeight = FontWeight.Bold,
color = Color.Blue
)
}
Image
Q: How do you display a circular local image?
@Composable
fun CircularImage() {
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = "App Icon",
modifier = Modifier
.size(100.dp)
.clip(CircleShape)
)
}
Column
Q: How do you arrange multiple Text elements vertically?
@Composable
fun ColumnExample() {
Column(modifier = Modifier.padding(16.dp)) {
Text("Item One")
Text("Item Two")
Text("Item Three")
}
}
Card
Q: How do you create a simple Card with some text?
@Composable
fun SimpleCard() {
Card(
modifier = Modifier.padding(16.dp),
elevation = CardDefaults.cardElevation(8.dp)
) {
Text("This is inside a Card", modifier = Modifier.padding(16.dp))
}
}
Intermediate Level
Text
Q: How do you make part of a text clickable?
@Composable
fun ClickableTextExample() {
val annotatedString = buildAnnotatedString {
append("Visit ")
pushStringAnnotation(tag = "URL", annotation = "https://developer.android.com")
withStyle(SpanStyle(color = Color.Blue, textDecoration = TextDecoration.Underline)) {
append("Android Docs")
}
pop()
}
ClickableText(
text = annotatedString,
onClick = { offset ->
annotatedString.getStringAnnotations("URL", offset, offset).firstOrNull()?.let {
println("Clicked URL: ${it.item}")
}
}
)
}
Image
Q: How do you load an image from a URL using Coil?
@Composable
fun NetworkImage() {
AsyncImage(
model = "https://picsum.photos/300",
contentDescription = "Random Image",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(200.dp)
.clip(RoundedCornerShape(16.dp))
)
}
Column
Q: How do you build a scrollable list using LazyColumn?
@Composable
fun LazyColumnExample() {
val items = List(20) { "Item #$it" }
LazyColumn(modifier = Modifier.fillMaxSize()) {
items(items) { item ->
Text(item, modifier = Modifier.padding(8.dp))
}
}
}
Card
Q: How do you create an expandable Card?
@Composable
fun ExpandableCard() {
var expanded by remember { mutableStateOf(false) }
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.clickable { expanded = !expanded },
elevation = CardDefaults.cardElevation(8.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Text("Click to ${if (expanded) "Collapse" else "Expand"}")
AnimatedVisibility(visible = expanded) {
Text("This is extra content shown when expanded.")
}
}
}
}
Advanced Level
Text
Q: How do you animate text size when clicked?
@Composable
fun AnimatedTextSize() {
var large by remember { mutableStateOf(false) }
val size by animateDpAsState(targetValue = if (large) 32.dp else 16.dp)
Text(
text = "Tap me!",
fontSize = size.value.sp,
modifier = Modifier
.clickable { large = !large }
.padding(16.dp)
)
}
Image
Q: How do you animate image swipe like a Tinder card?
@Composable
fun SwipeableImageCard() {
val offsetX = remember { Animatable(0f) }
Box(
Modifier
.fillMaxWidth()
.height(200.dp)
.pointerInput(Unit) {
detectHorizontalDragGestures { _, dragAmount ->
launch { offsetX.snapTo(offsetX.value + dragAmount) }
}
}
) {
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = null,
modifier = Modifier
.offset { IntOffset(offsetX.value.toInt(), 0) }
.fillMaxSize()
)
}
}
Column
Q: How do you add sticky headers in a list with LazyColumn?
@Composable
fun StickyHeaderList() {
val sections = mapOf(
"Fruits" to listOf("Apple", "Banana"),
"Vegetables" to listOf("Carrot", "Lettuce")
)
LazyColumn {
sections.forEach { (header, items) ->
stickyHeader {
Text(
text = header,
modifier = Modifier
.background(Color.LightGray)
.padding(8.dp)
)
}
items(items) {
Text(text = it, modifier = Modifier.padding(8.dp))
}
}
}
}
Card
Q: How do you animate a card’s content size when toggled?
@Composable
fun AnimatedCardContent() {
var expanded by remember { mutableStateOf(false) }
Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.clickable { expanded = !expanded }
.animateContentSize(),
elevation = CardDefaults.cardElevation(8.dp)
) {
Column(modifier = Modifier.padding(16.dp)) {
Text("Tap to ${if (expanded) "Collapse" else "Expand"}")
if (expanded) {
Text("This is the expanded content.")
}
}
}
}

Comments
Post a Comment