我正在嘗試設定ic_remove_selected_photo在盒子的頂端
![對齊框中的專案 [Jetpack Compose]](https://img.uj5u.com/2021/11/10/26a3210043374f7c8fb611dc0c3d84fb.png)
我所取得的成就:
![對齊框中的專案 [Jetpack Compose]](https://img.uj5u.com/2021/11/10/21b75546f055431db78af8297c35f329.png)
代碼:
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))
}
}
我如何remove icon在影像上設定?
uj5u.com熱心網友回復:
![對齊框中的專案 [Jetpack Compose]](https://img.uj5u.com/2021/11/10/198d1a2a842d4219b3c54d4a6357c082.png)
@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 = "",
)
}
}
}
uj5u.com熱心網友回復:
使用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 = "",
)
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/354358.html
