TheJadav

Components in android jetpack compose – similar component to android

Components in android jetpack compose - similar component to android

As android announced jetpack compose, I have read about it and checked how it works. It’s structure looks similar to flutter development, like only one file for UI and code. But it is still in alpha version so we can only use it in canary channel.

I have listed some of components and parameters(28th Jan 2021), which are use full for building app:

Text

Text("Hello There")

Column – to display in vertical format

Column {
        Text("Hello")
        Text("There")
    }

Row – to display in horizontal format

Row {
        Text("Hello")
        Text("There")
    }

Spacer – define empty space 

Spacer(Modifier.preferredSize(padding))

Card – same as CardView in android

Card(elevation = 4.dp) { /*...*/  }

ScrollableColumn & ScrollableRow – ScrollView or HorizontalScrollView

ScrollableColumn(Modifier.fillMaxSize()) {
        /*....*/
}

LazyColumnFor & LazyRowFor – Recyclerview or HorizontalRecyclerView

LazyColumnFor(list) { item ->
    /*....*/
}

Scaffold – This allows us to use material components like drawer, appbar, fab button etc.

Scaffold (
        drawerContent = { /*...*/ },
        topBar = { /*...*/ },
        bodyContent = { /*...*/ }
    )

ConstraintLayout  – yes it is available in compose also

Modifier – A great tool for appearance and behavior changes, all our xml attributes can be found here

Divider – Used to show divider between two components

LazyColumn & LazyRow – LazyColumnFor internally used LazyColumn and so LazyRow

Button 

Button(onClick = {  }) {
        Text("")
}

Image – as ImageView

Important note: 

LazyColumn doesn’t recycle its children like RecyclerView. It emits new Composables as you scroll through it and is still performant as emitting Composables is relatively cheap compared to instantiating Android Views.

Share this content:

Share:

More Posts

Introduction to Kotlin: A Versatile and Modern Programming Language

Kotlin, a versatile and modern programming language, offers developers a concise, safe, and interoperable coding experience. With features like null safety, extension functions, and coroutines, Kotlin enhances productivity and readability, making it an attractive choice for Android development and beyond. Whether you’re new to programming or an experienced developer, exploring Kotlin opens up a world of possibilities for building robust and expressive applications.

Mastering the Android Activity Lifecycle: A Comprehensive Guide

The Android Activity Lifecycle is a fundamental concept for Android developers. It defines how an Activity behaves during its lifecycle, from creation to destruction. Understanding the Activity Lifecycle is crucial for managing resources efficiently and delivering a smooth user experience. In this blog post, we’ll briefly introduce the different states an Activity can be in and the main callback methods associated with each state. Let’s dive in and explore this important aspect of Android app development!

Table of Contents

Send Us A Message