gpt4 book ai didi

Android 设计器渲染问题与 TextInputLayout : java. lang.IllegalArgumentException : weight is out of range of [0, 1000]

转载 作者:行者123 更新时间:2023-12-04 23:54:44 31 4
gpt4 key购买 nike

今天打开 Android Studio 时,我感到很惊讶——我看不到布局的预览:

enter image description here

我认为这只是一个简单的修复:

  • 重新加载设计器
  • 清理和构建项目
  • 使缓存失效并重新启动

虽然这些都没有解决问题。

虽然我仍然遇到问题,但我也遇到过其他人遇到渲染问题并尝试了各种解决方案。

奇怪的是,每当我从布局中删除 TextInputLayout 小部件时,渲染问题就会消失:

(以下是导致问题的布局之一。)

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fragmentNewCanvas_rootLayout"
tools:context=".fragments.newcanvas.NewCanvasFragment">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/fragmentNewCanvas_projectTitleTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:hint="@string/fragmentNewCanvas_project_name_str"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fragmentNewCanvas_projectTitleTextInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/fragmentNewCanvas_spanCountTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:layout_marginEnd="24dp"
android:hint="@string/fragmentNewCanvas_span_count_str"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/fragmentNewCanvas_projectTitleTextInputLayout">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/fragmentNewCanvas_spanCountTextInputEditText"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/fragmentNewCanvas_doneButton"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
android:text="@string/str_button_done"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是演示问题的 gif:

enter image description here

不包含 TextInputLayout 的布局呈现良好,但包含的布局会导致问题。

堆栈跟踪:

java.lang.IllegalArgumentException: weight is out of range of [0, 1000] (too low)
at com.android.internal.util.Preconditions.checkArgumentInRange(Preconditions.java:527)
at android.graphics.Typeface.create_Original(Typeface.java:979)
at android.graphics.Typeface_Delegate.create(Typeface_Delegate.java:123)
at android.graphics.Typeface.create(Typeface.java:979)
at com.google.android.material.internal.CollapsingTextHelper.maybeCloneWithAdjustment(CollapsingTextHelper.java:532)
at com.google.android.material.internal.CollapsingTextHelper.setCollapsedTypefaceInternal(CollapsingTextHelper.java:475)
at com.google.android.material.internal.CollapsingTextHelper.setTypefaces(CollapsingTextHelper.java:459)
at com.google.android.material.textfield.TextInputLayout.setEditText(TextInputLayout.java:1467)
at com.google.android.material.textfield.TextInputLayout.addView(TextInputLayout.java:888)
at android.view.ViewGroup.addView(ViewGroup.java:5048)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1131)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:1130)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:72)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1101)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1088)
at android.view.LayoutInflater.inflate(LayoutInflater.java:686)
at android.view.LayoutInflater.inflate(LayoutInflater.java:505)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:361)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:436)
at com.android.tools.idea.layoutlib.LayoutLibrary.createSession(LayoutLibrary.java:121)
at com.android.tools.idea.rendering.RenderTask.createRenderSession(RenderTask.java:727)
at com.android.tools.idea.rendering.RenderTask.lambda$inflate$7(RenderTask.java:883)
at com.android.tools.idea.rendering.RenderExecutor$runAsyncActionWithTimeout$2.run(RenderExecutor.kt:187)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

如果有人有解决方案,将不胜感激。

最佳答案

改变

实现 'com.google.android.material:material:x.x.x-alpha'

实现 'com.google.android.material:material:1.5.0'

关于Android 设计器渲染问题与 TextInputLayout : java. lang.IllegalArgumentException : weight is out of range of [0, 1000],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71058519/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com