android 如何最大化图像上的按钮点击jetpack合成?

bvk5enib  于 2022-11-20  发布在  Android
关注(0)|答案(1)|浏览(136)

我有一个GlideImage,它在一个盒子里。在那个盒子里,还有一个带图标的按钮。我希望,当我点击这个按钮时,图像被最大化,并占据整个屏幕,在右下角有一个按钮,可以最小化它。我还想放大它。有人知道我怎么做吗?在Jetpack Compose的当前状态下,这是否可能?
我给你留下了生成Box的代码,包括图像和图标。
提前感谢您的帮助。

@ExperimentalGlideComposeApi
@Composable
fun BuildImage(imageUrl: String) {
    Box(
        modifier = Modifier
            .padding(vertical = 25.dp, horizontal = 25.dp)
            .background(
                brush = Brush.linearGradient(
                    listOf(
                        Color.Gray,
                        Color.White
                    )
                ),
                shape = RoundedCornerShape(14.dp)
            )
            .clip(RoundedCornerShape(14.dp))
    ) {
        GlideImage(
            model = imageUrl,
            contentDescription = null,
            contentScale = ContentScale.FillBounds
        )

        Box(modifier = Modifier.matchParentSize(), contentAlignment = Alignment.BottomEnd) {
            IconButton(
                onClick = { /* TO IMPLEMENT */ },
                modifier = Modifier
                    .padding(11.dp)
                    .background(Color.Blue, RoundedCornerShape(3.dp))
                    .clip(RoundedCornerShape(3.dp))
                    .size(52.dp)
            ) {
                Icon(
                    painter = painterResource(id = R.drawable.maximize),
                    contentDescription = null,
                    tint = Color.Unspecified
                )
            }
        }
    }
}
vnjpjtjt

vnjpjtjt1#

您可以通过以下操作完成此操作:

@OptIn(ExperimentalGlideComposeApi::class)
@Composable
fun Q74501531() {
    val configuration = LocalConfiguration.current
    val screenWidth = configuration.screenWidthDp.dp // Get screen width as dp from local configuration
    val screenHeight = configuration.screenHeight.dp // You can also get screen height but for demo it's unused

    Column(
        modifier = Modifier.fillMaxSize()
    ) {
        var isExpanded by remember { mutableStateOf(false) } // Trigger state for change width and height
        val width by animateDpAsState(if (isExpanded) screenWidth else screenWidth / 3)
        val height by animateDpAsState(if (isExpanded) screenWidth / 2 else screenWidth / 5)

        GlideImage(
            modifier = Modifier.size(width, height),
            model = "https://upload.wikimedia.org/wikipedia/commons/9/9a/Gull_portrait_ca_usa.jpg",
            contentDescription = null,
            contentScale = ContentScale.Crop
        )

        Spacer(Modifier.weight(1f))

        TextButton(
            modifier = Modifier
                .fillMaxWidth()
                .padding(horizontal = 8.dp),
            onClick = { isExpanded = !isExpanded }
        ) {
            Text("Toggle")
        }
    }
}

演示:https://youtu.be/PwPagLi8nEs

相关问题