Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JetPack Compose - remove extra padding from view

I have a few Icons in a row

    Row {
    IconButton {
        Icon(
            painter = painterResource(R.drawable.im1)
        )
    },
    IconButton {
        Icon(
            painter = painterResource(R.drawable.im2)
        )
    }
}

But when it's displayed the distance between 2 icons in the row is bigger then I expect. I feel like there is 32dp spacer between them. How can I decrease the distance between 2 icons inside a row?

like image 709
Rainmaker Avatar asked Jul 12 '26 23:07

Rainmaker


2 Answers

The space between the 2 icons it is not a padding and depends by the default size of the IconButton.
It is due to accessibility touch targets and allows the correct minimum touch target size.
You can change it disabling the LocalMinimumTouchTargetEnforcement and applying a Modifier.size(24.dp) to the IconButton:

CompositionLocalProvider(LocalMinimumTouchTargetEnforcement provides false){
    Row {
        IconButton(modifier = Modifier.size(24.dp),
            onClick = {}) {
            Icon(
                painter = painterResource(R.drawable.ic_add_24px),""
            )
        }
        IconButton(modifier = Modifier.size(24.dp),
            onClick = {}) {
            Icon(
                painter = painterResource(R.drawable.ic_add_24px),""
            )
        }
    }
}

As alternative you can use an Icon with the Modifier.clickable:

Row {
    Icon(
            painter = painterResource(R.drawable.ic_add_24px),"",
        modifier = Modifier.clickable (onClick = {} )
        )
    Icon(
            painter = painterResource(R.drawable.ic_add_24px),"",
        modifier = Modifier.clickable (onClick = {} )
        )
}

enter image description here

like image 154
Gabriele Mariotti Avatar answered Jul 14 '26 13:07

Gabriele Mariotti


Both LocalMinimumTouchTargetEnforcement and LocalMinimumInteractiveComponentEnforcement are deprecated, you should use LocalMinimumInteractiveComponentSize and set its value to 0.dp like this:

CompositionLocalProvider(LocalMinimumInteractiveComponentSize provides 0.dp) {
    // Component
}
like image 38
hosseinAmini Avatar answered Jul 14 '26 11:07

hosseinAmini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!