简体   繁体   English

如何在 JetpackCompose “行”或“列”中设置 ClipToBounds “false”

[英]How to set ClipToBounds "false" in JetpackCompose "row" or "column"

    Row(modifier = Modifier.height(58.dp).fillMaxWidth().notClip()) {
                Icon(
                    painter = painterResource(id = R.drawable.ic_launcher_foreground),
                    contentDescription = null,
                    modifier = Modifier
                        .height(100.dp)
                        .width(100.dp)
                        .clip(shape = CircleShape)
                    .clickable(
                        onClick = {
                        Toast
                            .makeText(
                                this@MainActivity,
                                "YOU clicked android button",
                                Toast.LENGTH_SHORT
                            )
                            .show();
                    },
                    ))
            }

In my above code, im trying to show ripples of the button outside the row constraints (Just like in github-mobile app's bottom navigation bar; when you click a button in the bottomNavigation bar it shows ripple outside the BottomNavigation bar) ie height(60.dp) , however its not working.在我上面的代码中,我试图在行约束之外显示按钮的涟漪(就像在 github-mobile 应用程序的底部导航栏中一样;当您单击底部导航栏中的按钮时,它会在底部导航栏外显示涟漪)height(60.dp) ,但是它不起作用。 I researched a bit and created own extension function as我研究了一下并创建了自己的扩展 function 作为

fun Modifier.notClip()= graphicsLayer(clip = false) ;

and use it on the Row's modifier to disable clipping, but the Row still clips the ripple that is to be shown outside the Row's constraints.并在 Row 的修改器上使用它来禁用剪辑,但 Row 仍会剪辑要在 Row 约束之外显示的波纹。 Someone help,,有人帮忙,, ` `

In the clickable modifier you can specify the Indication parameter.clickable修饰符中,您可以指定Indication参数。 You can use the default ripple defined by rememberRipple changing the bounded parameter.您可以使用通过rememberRipple更改bounded参数定义的默认波纹。

    Row(
        modifier = Modifier.height(58.dp).fillMaxWidth().background(Color.Yellow)
    ) {
        Icon(
            painter = painterResource(id = R.drawable.ic_launcher_foreground),
            contentDescription = null,
            modifier = Modifier
                .clickable(
                    interactionSource = interactionSource,
                    indication = rememberRipple(
                        //radius= 300.dp,
                        bounded = false),
                    onClick = { /* .. */ })
                .height(100.dp)
                .width(100.dp)
                .clip(shape = CircleShape)

        )
    }

在此处输入图像描述

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

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