MainActivity.kt
package com.cfsuman.jetpackcompose
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
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(){
Column(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFF8F9779))
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.flower9),
contentDescription = "Localized description",
contentScale = ContentScale.Crop,
modifier = Modifier
.clip(shape = RoundedCornerShape(16.dp))
.fillMaxWidth()
.height(180.dp)
.background(Color.LightGray)
)
Image(
painter = painterResource(id = R.drawable.flower9),
contentDescription = "Localized description",
contentScale = ContentScale.Inside,
modifier = Modifier
.clip(shape = RoundedCornerShape(16.dp))
.fillMaxWidth()
.height(180.dp)
.background(Color.LightGray)
)
Image(
painter = painterResource(id = R.drawable.flower9),
contentDescription = "Localized description",
contentScale = ContentScale.FillBounds,
modifier = Modifier
.clip(shape = RoundedCornerShape(16.dp))
.fillMaxWidth()
.height(180.dp)
.background(Color.LightGray)
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Image shape
- jetpack compose - Image tint
- jetpack compose - Image background
- jetpack compose - Image from URL
- jetpack compose - LazyColumn content spacing padding
- jetpack compose - LazyRow content padding spacing
- jetpack compose - LazyVerticalGrid
- jetpack compose - ExpandIn ShrinkOut animation
- jetpack compose - SlideIn SlideOut animation
- jetpack compose - Infinite repeatable animation
- jetpack compose - Combine multiple transitions
- jetpack compose - AnimateContentSize customization
- jetpack compose - Spring animation
- jetpack compose - AnimateOffsetAsState
- jetpack compose - Infinite color animation