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.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.CutCornerShape
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.Brush
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(0xFFFFF0F5))
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(32.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
val sweepGradientBrush = Brush.sweepGradient(
colors = listOf(Color.Red, Color.Green, Color.Yellow)
)
Image(
painter = painterResource(id = R.drawable.flower5),
contentDescription = "Localized description",
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth(0.9f)
.height(150.dp)
.clip(RoundedCornerShape(12.dp))
.border(
8.dp,
sweepGradientBrush,
RoundedCornerShape(12.dp)
)
)
val verticalGradientBrush = Brush.verticalGradient(
colors = listOf(Color(0xFFFF5470), Color(0xFFEEDC82))
)
Image(
painter = painterResource(id = R.drawable.flower5),
contentDescription = "Localized description",
contentScale = ContentScale.Crop,
modifier = Modifier
.fillMaxWidth(0.9f)
.height(150.dp)
.clip(CutCornerShape(12.dp))
.border(
6.dp,
verticalGradientBrush,
CutCornerShape(12.dp)
)
)
val linearGradientBrush = Brush.linearGradient(
colors = listOf(Color(0xFFED2939), Color(0xFFFFFF66))
)
Image(
painter = painterResource(id = R.drawable.flower5),
contentDescription = "Localized description",
contentScale = ContentScale.Crop,
modifier = Modifier
.size(200.dp)
.clip(CircleShape)
.border(10.dp,linearGradientBrush, CircleShape)
)
}
}
@Preview
@Composable
fun ComposablePreview(){
//MainContent()
}
}
- jetpack compose - Image clickable
- jetpack compose - Image border
- jetpack compose - Image shadow elevation
- jetpack compose - Image size
- jetpack compose - String resource plurals
- jetpack compose - Get dimension resource
- jetpack compose - Get color resource
- jetpack compose - ExpandIn ShrinkOut animation
- jetpack compose - SlideIn SlideOut animation
- jetpack compose - Infinite repeatable animation
- jetpack compose - Column border
- jetpack compose - Column spacing
- jetpack compose - Column scrollable
- jetpack compose - Row spacing
- jetpack compose - Row scrolling