Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw a line in jetpack compose

Tags:

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?

like image 941
Mahdi-Malv Avatar asked Nov 17 '19 07:11

Mahdi-Malv


People also ask

How do you draw a line on a jetpack?

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.

Why is Jetpack Compose better than XML?

1. It allows you to do more with less code compared to xml. 2. Jetpack compose is compatible with all your existing code.

Is Jetpack Compose hard?

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.

What is LazyColumn in Jetpack Compose?

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.


1 Answers

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)                  }             }         }      }  } 
like image 71
Rajnish suryavanshi Avatar answered Sep 21 '22 05:09

Rajnish suryavanshi