[英]How remove extra padding above Jetpack Compose OutlinedTextField?
[英]JetPack Compose - remove extra padding from view
我row
有幾個圖標
Row {
IconButton {
Icon(
painter = painterResource(R.drawable.im1)
)
},
IconButton {
Icon(
painter = painterResource(R.drawable.im2)
)
}
}
但是當它顯示時, row
中 2 個圖標之間的距離比我預期的要大。 我覺得它們之間有 32dp 的間隔。 如何減少row
內 2 個圖標之間的距離?
2 個圖標之間的空間不是填充,取決於IconButton
的默認大小。
這是由於可訪問性觸摸目標並允許正確的最小觸摸目標大小。
您可以更改它以禁用LocalMinimumTouchTargetEnforcement
並將Modifier.size(24.dp)
應用於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),""
)
}
}
}
作為替代方案,您可以將Icon
與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 = {} )
)
}
如果您希望控制確切的距離,可以實現Layout
,讓您完全控制偏移量(是的,您也可以只使用偏移量修飾符,但我發現這更有希望。
Layout(
content = {
IconButton {
Icon(
painter = painterResource(R.drawable.im1)
)
},
IconButton {
Icon(
painter = painterResource(R.drawable.im2)
)
}
}
){ measurables, constraints ->
val icon1 = measurables[0].measure(constraints)
val icon2 = measurables[1].measure(constraints)
layout(constraints.maxWidth, constraints.maxHeight){ //Change these to suit your requirements
//Use place(x, y) to specify exact co-ordinates within the container
icon1.place(0, 0)
icon2.place(icon1.width, 0) //Places Directly where icon1 ends
/*If padding still appears, you can subtract some function from the second icon's starting point to make it even closer than the edge of iicon1
*/
}
應該是這個!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.