本文主要是介绍03. Compose 可组合组件之Card 图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
01. Compose 可组合组件之Row And Column
02. Compose 可组合组件之 属性 modifier
03. Compose 可组合组件之Card 图片
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)}}}@Composablefun 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))}}}}
}
这篇关于03. Compose 可组合组件之Card 图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!