Using XML layout, you could use a View object with colored background to draw a line.
<View android:width="match_parent" android:height="1dp" android:background="#000000" />
How can we draw a horizontal or vertical line in Jetpack compose?
In Android, a Canvas is used when we need to draw objects of different shapes and types. Canvas is a class in Android that performs 2D drawings of different objects onto the screen. It can also be used for drawing a straight line between two given points.
1. It allows you to do more with less code compared to xml. 2. Jetpack compose is compatible with all your existing code.
1 - Creating your first Compose project is easyCreating your first Jetpack Compose project is surprisingly easy. Just download the latest Canary version of Android studio and select a new Compose project from the list of possible Android projects. To start you'll have a simple “Hello world!” Text composable.
A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.
You can use
Divider Composable
method for Horizontal line like below.
Divider(color = Color.Blue, thickness = 1.dp)
Example :
@Composable fun drawLine(){ MaterialTheme { VerticalScroller{ Column(modifier = Spacing(16.dp), mainAxisSize = LayoutSize.Expand) { (0..3).forEachIndexed { index, i -> Text( text = "Draw Line !", style = TextStyle(color = Color.DarkGray, fontSize = 22.sp) ) Divider(color = Color.Blue, thickness = 2.dp) } } } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With