使用Android Studio Giraffe 2022.3.1 所以使用预设推荐的编译器与这个版本的android studio
查找关于
.align()
能够在列/行范围中使用的相互矛盾的在线信息。有人说它不起作用或只能在 BoxScope 内起作用。
然而,Android 开发人员介绍 CODELAB 使用此代码,并推荐在 columnScope 中使用
Modifier.align()
,这会引发相同的错误:
错误
无法访问“ColumnScopeInstance”:它位于“androidx.compose.foundation.layout”内部
未解决的参考:结束
import androidx.compose.foundation.layout.ColumnScopeInstance.align // import causing the first error
{ //Column Scope
Text(
text = message,
fontSize = 100.sp,
lineHeight = 116.sp,
textAlign = TextAlign.Center
)
Text(
text = from,
fontSize = 36.sp,
modifier = Modifier
.padding(16.dp)
.offset(90.dp)
.align(Alignment.End), // Error on this line
textAlign = TextAlign.Left
)
}
更新:在同一 ide 版本中开始一个新项目使它可以工作,但我的旧项目刚刚损坏,我怎么知道出了什么问题以及如何在我的旧项目中解决这个问题。
对齐只能在 Box() 组件内使用。
就像这样:
Box{
Text(
text = message,
fontSize = 100.sp,
lineHeight = 116.sp,
textAlign = TextAlign.Center
)
Text(
text = from,
fontSize = 36.sp,
modifier = Modifier
.padding(16.dp)
.offset(90.dp)
.align(Alignment.End), // Error on this line
textAlign = TextAlign.Left
)
}
您也可以查看此链接: