我正在尝试在 Jetpack Compose 中的圆圈内绘制文本。
我画了一个圆,中心是画布的中心。
现在我想精确地在圆的中心绘制文本。
drawTextJetpack compose中的函数具有canvas参数topLeft,该参数需要Offset包含文本的矩形的左上角。我知道我不能通过圆心作为偏移量topLeft,如果我这样做,结果将如下所示,这不是我想要的。
我希望文本恰好绘制在圆的中心。
这是代码:
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Green.copy(alpha = 0.2f))
.padding(36.dp),
contentAlignment = Alignment.Center
) {
val textMeasurer = rememberTextMeasurer()
val textToDraw = "A"
Canvas(modifier = Modifier.fillMaxSize()) {
drawCircle(
center = Offset(
x = center.x,
y = center.y
),
radius = 350f,
color = Color.Blue,
style = Stroke(
width = 8f
)
)
drawText(
textMeasurer = textMeasurer,
text = textToDraw,
style = TextStyle( …Run Code Online (Sandbox Code Playgroud) android drawtext android-canvas android-jetpack-compose android-jetpack-compose-canvas
当我购买新笔记本电脑时,为了将我的 android studio 项目从旧笔记本电脑复制到新笔记本电脑,我只需将 AndroidStudioProjects 文件夹中的所有项目复制到新笔记本电脑中的相应文件夹中。
通常它曾经有效。但这一次,我在 gradle 同步时遇到了新的错误。
当我尝试运行复制的项目时,在 gradle 同步过程中,出现以下错误。
Unable to load class 'org.jetbrains.kotlin.config.LanguageVersion'.
This is an unexpected error. Please file a bug containing the idea.log file.
Run Code Online (Sandbox Code Playgroud)
和
org/jetbrains/kotlin/config/LanguageVersion
> org.jetbrains.kotlin.config.LanguageVersion
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/config/LanguageVersion
at org.jetbrains.kotlin.gradle.plugin.sources.FragmentConsistencyChecks.<init>(ConsistencyChecker.kt:24)
at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetKt.<clinit>(DefaultKotlinSourceSet.kt:210)
at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet.<init>(DefaultKotlinSourceSet.kt:62)
at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetFactory.doCreateSourceSet(KotlinSourceSetFactory.kt:162)
at org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSetFactory.doCreateSourceSet(KotlinSourceSetFactory.kt:65)
at org.jetbrains.kotlin.gradle.plugin.sources.KotlinSourceSetFactory.create(KotlinSourceSetFactory.kt:30)
at org.jetbrains.kotlin.gradle.plugin.sources.KotlinSourceSetFactory.create(KotlinSourceSetFactory.kt:23)
//I have trimmed the stack trace.
Caused …Run Code Online (Sandbox Code Playgroud)