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.rotate
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(0xFFF0FFFF))
)
{
rotate(
degrees = 45F,
//pivot = Offset(size.width/2,size.height/2)
){
drawRect(
color = Color(0xFF007FFF),
topLeft = Offset(
x = 50.dp.toPx(),
y = size.height/2 - 50.dp.toPx()
),
size = Size(
width = size.width - 100.dp.toPx(),
height = 100.dp.toPx()
)
)
}
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - LazyColumn scroll to top bottom
- jetpack compose - Animate content size
- jetpack compose - FadeIn FadeOut animation
- jetpack compose - Animation duration
- jetpack compose - animateFloatAsState
- jetpack compose - Repeatable animation
- jetpack compose - Snap animation
- jetpack compose - AnimateColorAsState
- jetpack compose - AnimateColorAsState duration
- jetpack compose - Infinite float animation
- jetpack compose - Animation start delay
- jetpack compose - Draw circle on canvas
- jetpack compose - Draw rectangle on canvas
- jetpack compose - Draw rounded rectangle on canvas
- jetpack compose - Draw oval on canvas