簡體   English   中英

如何在 Jetpack Compose 中按高度縮放圖標寬度

[英]How to scale icon width by height in Jetpack Compose

我正在嘗試按高度縮放圖標寬度。 我試圖添加 contentScale 修飾符,但它不知道。

Icon(
           painter = painterResource(id = id),
           contentDescription = null,
           tint = Color.White,
           //contentScale = ContentScale.Fit,
           modifier = Modifier .fillMaxHeight(0.6f)
                               .align(CenterVertically).border(2.dp,Color.Black, RectangleShape)
    )

想象一下它的樣子 - 左邊的圖標應該被縮放以適應黑框的高度: 左側的圖標應縮放以適合黑框的高度

確保您的圖標是正方形就足夠了。

Modifier
    .fillMaxHeight(0.6f)
    .aspectRatio(1f) // make the width same as the height
    ... // your other modifiers

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM