我希望小部件右对齐,但只使用一列。有没有其他方法可以对齐这些项目?
代码:
Column(LayoutPadding(20.dp)) {
Align(alignment = Alignment.TopRight) {
Text(text = "0")
Text(text = "testOperation")
}
}
结果:
(RIGHT ALIGNED) 0
预期:
(RIGHT ALIGNED) 0
(RIGHT ALIGNED) testOperation
答案 0 :(得分:0)
您应该尝试这样
Align(alignment = Alignment.TopRight) {
Column(LayoutPadding(20.dp)){
Text(text = "0")
Text(text = "testOperation")
}
}
还是这样,取决于您的用法。
Column(LayoutPadding(20.dp)) {
Align(alignment = Alignment.TopRight) {
Column(){
Text(text = "0")
Text(text = "testOperation")
}
}
}
您可以使用Alignment.TopRight,BottomRight等来对齐每个文本。
Column(LayoutPadding(20.dp)) {
Column(){
Text(text = "0")
Align(alignment = Alignment.TopRight) {
Text(text = "testOperation")
}
}
}
答案 1 :(得分:0)
使用1.0.0-alpha01
时,请使用类似以下内容:
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.End
) {
Box (){
Text(
text = "First item",
modifier = Modifier.padding(16.dp).gravity(align = Alignment.Start)
)
Text(
text = "Second item",
modifier = Modifier.padding(16.dp).gravity(align = Alignment.Start)
)
Text(
text = "Third item",
modifier = Modifier.padding(16.dp).gravity(align = Alignment.Start)
)
}
}