pap*_*e96 6 android android-layout android-studio android-constraintlayout
我正在玩弄 提供的圆形定位ConstraintLayout。在下面的示例应用程序中,我有一个TextView在屏幕上居中和一个半径为50dp s、角度为45 度ImageViews 的圆形约束。它应该受到完全约束,因为不再有以 开头的 XML 属性,所以我假设我已经完全声明了它的预期位置。但是,Android Studio 向我发出以下警告:TextViewapp:layout_constraintCircleImageView
这种观点不受约束。它只有设计时位置,因此除非添加约束,否则它将在运行时跳转到 (0,0)
运行应用程序证明我是对的,因为受约束的视图位于正确的位置并且不会跳转到布局的开头。
所以我的问题是:我是否缺少任何额外的约束,或者 Android Studio 是否因某种原因无法识别循环约束有效?
XML 布局示例:
<?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"
tools:context=".MainActivity">
<TextView
android:id="@+id/hello_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="@drawable/ic_launcher_background"
app:layout_constraintCircle="@id/hello_text"
app:layout_constraintCircleAngle="45"
app:layout_constraintCircleRadius="50dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我自己尝试过这个,我只能说这是 android studio lint 的错误。
由于存在角度和半径,因此定义的ImageView相对于 的位置TextView是固定的。
现在你可以通过添加来抑制 lint 错误
tools:ignore="MissingConstraints"
Run Code Online (Sandbox Code Playgroud)
到图像视图。
最好在问题跟踪器中报告此问题,如下
Android Public Tracker > App Development > Android Studio > Lint
Run Code Online (Sandbox Code Playgroud)
实际上,在使用 Parcelize 时,我也遇到了类似的情况(lint 错误),这是在此处报告的。
| 归档时间: |
|
| 查看次数: |
1226 次 |
| 最近记录: |