简体   繁体   English

Jetpack compose 如何将卡片中的线圈图像表面与卡片底部对齐?

[英]Jetpack compose how to allign surface over coil image in card to the bottom of the card?

I can't come up with a solution how to move the Surface object to the bottom of the card (image), and maybe add some padding from the bottom.我无法想出如何将Surface object 移动到卡片底部的解决方案(图像),并且可能从底部添加一些填充。

This is what it should look like:它应该是这样的: 在此处输入图像描述

Here is the code:这是代码:

Card(modifier = Modifier
                .fillMaxSize()
                .padding(8.dp),
                shape = RoundedCornerShape(12.dp),
                elevation = 4.dp,
                border = BorderStroke(2.dp, AppColors.mMain)) {

                AsyncImage(model = ImageRequest.Builder(LocalContext.current)
                    .data(it.background_image)
                    .crossfade(true)
                    .build(),
                    contentDescription = "Game Image")

                Surface(modifier = Modifier.fillMaxWidth()
                    .height(50.dp)
                    .padding(start = 35.dp, end = 35.dp),
                color = AppColors.mMain,
                    border = BorderStroke(2.dp, Color.Black),
                shape = RoundedCornerShape(12.dp)) {

                }
            }

The modified code is as follows :修改后的代码如下

Card(modifier = Modifier
                    .fillMaxSize()
                    .padding(8.dp),
                    shape = RoundedCornerShape(12.dp),
                    elevation = 4.dp,
                    border = BorderStroke(2.dp, AppColors.mMain)
                ) {
                    Box {
                        AsyncImage(model = ImageRequest.Builder(LocalContext.current)
                            .data(it.background_image)
                            .crossfade(true)
                            .build(),
                            contentDescription = "Game Image")
                        Surface(modifier = Modifier.fillMaxWidth()
                            .height(50.dp)
                            .align(Alignment.BottomCenter)
                            .padding(start = 35.dp, end = 35.dp, bottom = 15.dp),
                            color = AppColors.mMain,
                            border = BorderStroke(2.dp, Color.Black),
                            shape = RoundedCornerShape(12.dp)) {

                        }
                    }
                }

Use Box inside your card, put Image and Surface inside it and add.align(Alignment.BottomCenter) to your Surface's modifier.在卡片中使用 Box,将 Image 和 Surface 放入其中,并将 add.align(Alignment.BottomCenter) 添加到 Surface 的修饰符中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM