class ImageCardActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val painter = painterResource(id = R.drawable.sheep)
val des = "this is android test"
val title = "This is Title of image"
Box(
modifier = Modifier
.fillMaxWidth(0.5f)
.padding(16.dp)
) {
ShowImageCard(title = title, des = des, painter = painter)
}
}
}
@Composable
fun ShowImageCard(title: String, des: String, painter: Painter, modifier: Modifier = Modifier) {
Card(
modifier = modifier.fillMaxWidth(),
shape = RoundedCornerShape(15.dp),
elevation = 5.dp
) {
Box(modifier = Modifier.height(200.dp)) {
Image(
painter = painter,
contentDescription = des,
contentScale = ContentScale.Crop
)
Box(
modifier = Modifier
.fillMaxSize()
.background(
brush = Brush.verticalGradient(
colors = listOf(
Color.Transparent,
Color.Black
),
startY = 300f
)
)
)
Box(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
contentAlignment = Alignment.BottomStart
)
{
Text(title, style = TextStyle(color = Color.White, fontSize = 16.sp))
}
}
}
}
}