需求效果:文本的高度為50dp,并且文字垂直居中
根據需求寫出如下代碼:
Text(text = "你好,世界!", modifier = Modifier.height(50.dp), textAlign = TextAlign.Center)
運行后發現Text文字沒有垂直居中,設定textAlign為Center后是無效,
解決辦法是在Text外層加上Box后設定Box的屬性來實作需求中的效果
Box(modifier = Modifier.height(50.dp), contentAlignment = Alignment.Center) {
Text(text = "你好,世界!")
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/541915.html
標籤:其他
