DiagonalLinesView
is a custom Android view that draws diagonal lines across its canvas. It can be used to create visually appealing backgrounds or patterns in your Android applications.
- Draws evenly spaced diagonal lines in two directions (top-left to bottom-right and top-right to bottom-left).
- Fully customizable via code for line color and thickness.
- Easily integrated into any Android project.
- Can be used as a background for other views or as part of a
CardView
layout.
-
Add the
DiagonalLinesView
class to your project:- Copy the
DiagonalLinesView
code into your project under the desired package directory.
- Copy the
-
Use the view in your layout XML or programmatically.
Replace the package name ir.applicore.kingmovie
in the class file with your own package path.
You can use DiagonalLinesView
as a background in two ways:
To use DiagonalLinesView
in your XML layout:
<your.package.path.DiagonalLinesView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" />
If you are using Jetpack Compose, you can wrap DiagonalLinesView
in an AndroidView
composable:
import androidx.compose.ui.viewinterop.AndroidView
import your.package.path.DiagonalLinesView
@Composable
fun DiagonalLinesBackground() {
AndroidView(factory = { context ->
DiagonalLinesView(context).apply {
// Optional customization
}
}, modifier = Modifier.fillMaxSize())
}
You can use DiagonalLinesView
as a background inside a CardView
and place a button or other components on top of it. Example:
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="16dp"
app:cardElevation="8dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<your.package.path.DiagonalLinesView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Click Me" />
</FrameLayout>
</androidx.cardview.widget.CardView>
import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import your.package.path.DiagonalLinesView
@Composable
fun CardWithDiagonalLines() {
Card(
elevation = 8.dp,
modifier = Modifier.padding(16.dp)
) {
Box(modifier = Modifier.size(200.dp)) {
AndroidView(factory = { context ->
DiagonalLinesView(context)
}, modifier = Modifier.fillMaxSize())
Button(onClick = { /* Do something */ },
modifier = Modifier.align(Alignment.Center)) {
Text("Click Me")
}
}
}
}
To change the line color, modify the following line in the init()
method:
linePaint.setColor(Color.parseColor("#217CF3")); // Replace with your desired color
To adjust the line thickness, modify the following line in the init()
method:
linePaint.setStrokeWidth(2); // Replace with your desired thickness
Below is an example of a screen using the DiagonalLinesView
as a background:
Developed by ThingCoder.