简体   繁体   English

对齐框中的项目 [Jetpack Compose]

[英]Align item in box [Jetpack Compose]

I'm trying to set ic_remove_selected_photo at the TopEnd of the box我正在尝试在框的顶端设置ic_remove_selected_photo

在此处输入图片说明

What I have achieved:我所取得的成就:

在此处输入图片说明

Code:代码:

Box(modifier = Modifier.size(90.dp).padding(7.dp)) {
    Image(
        bitmap = bitmap.asImageBitmap(),
        modifier = Modifier
            .size(80.dp)
            .clip(RoundedCornerShape(6.dp)),
        contentScale = ContentScale.Crop,
    )

    IconButton(modifier = Modifier.align(Alignment.TopEnd).size(10.dp)) {
        Icon(painter = painterResource(id = R.drawable.ic_remove_selected_photo))
    }
}

How I can set remove icon on the image?如何在图像上设置remove icon

截屏

@Composable
fun ImageWithCloseButton() {
    Box(
        modifier = Modifier
            .background(LightGray)
            .padding(16.dp)
            .size(88.dp),
    ) {
        Image(
            painter = painterResource(
                id = R.drawable.ic_launcher_foreground,
            ),
            contentDescription = "",
            modifier = Modifier
                .align(Alignment.Center)
                .clip(RoundedCornerShape(16.dp))
                .background(Black)
                .size(80.dp),
            contentScale = ContentScale.Crop,
        )
        IconButton(
            onClick = {},
            modifier = Modifier
                .clip(CircleShape)
                .background(White)
                .align(Alignment.TopEnd)
                .size(16.dp)
        ) {
            Icon(
                imageVector = Icons.Rounded.Close,
                contentDescription = "",
            )
        }
    }
}

Use contentAlignment :使用contentAlignment

@Composable
fun ImageWithCloseButton() {
    Box(
        modifier = Modifier
            .background(LightGray)
            .padding(16.dp)
            .size(88.dp),
        contentAlignment = Alignment.TopEnd
    ) {
        Image(
            painter = painterResource(
                id = R.drawable.ic_launcher_foreground,
            ),
            contentDescription = "",
            modifier = Modifier
                .align(Alignment.Center)
                .clip(RoundedCornerShape(16.dp))
                .background(Black)
                .size(80.dp),
            contentScale = ContentScale.Crop,
        )
        IconButton(
            onClick = {},
            modifier = Modifier
                .clip(CircleShape)
                .background(White)
                .align(Alignment.TopEnd)
                .size(16.dp)
        ) {
            Icon(
                imageVector = Icons.Rounded.Close,
                contentDescription = "",
            )
        }
    }
}

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

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