MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MainContent()
}
}
@Composable
fun MainContent(){
Canvas(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFFBCEB1))
)
{
drawOval(
color = Color(0xFFD3212D),
topLeft = Offset(x = 25.dp.toPx(), y = 25.dp.toPx()),
size = Size(
width = size.width - 50.dp.toPx(),
height = size.height/2 - 50.dp.toPx()
)
)
drawOval(
color = Color(0xFF9966CC),
topLeft = Offset(
x = 25.dp.toPx(),
y = 25.dp.toPx() + size.height/2
),
size = Size(
width = size.width - 50.dp.toPx(),
height = size.height/2 - 50.dp.toPx()
),
style = Stroke(width = 10.dp.toPx())
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Draw circle on canvas
- jetpack compose - Draw rectangle on canvas
- jetpack compose - Draw rounded rectangle on canvas
- jetpack compose - Rotate canvas
- jetpack compose - Draw arc on canvas
- jetpack compose - Draw image on canvas
- jetpack compose - Draw text on canvas
- jetpack compose - Tap listener
- jetpack compose - Press listener
- jetpack compose - Column vertical scrolling
- jetpack compose - Swiping
- jetpack compose - Panning zooming rotating
- jetpack compose - Weight modifier
- jetpack compose - Button color
- jetpack compose - Button rounded corners