循环约束和“缺少约束”错误

时间:2019-08-26 14:44:31

标签: android android-studio android-layout android-constraintlayout

我正在玩ConstraintLayout提供的圆形定位。在下面的示例应用程序中,我有一个TextView在屏幕上居中,并且ImageView圆约束到TextView,半径为 50dp s,角度为 45度 s。应该完全限制它,因为没有其他以app:layout_constraintCircle开头的XML属性,因此我假设我已经完全声明了它的预期位置。但是,Android Studio在ImageView上给了我以下警告:

  

此视图不受限制。它只有设计时位置,因此除非您添加约束,否则它将在运行时跳至(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>

1 个答案:

答案 0 :(得分:2)

我自己尝试过这个,我只能说这是android studio lint的错误。

由于定义了角度和半径,FROM base AS final WORKDIR /app COPY --from=publish /app . EXPOSE 5000/tcp ENTRYPOINT ["dotnet", "CustomerAPI.dll"] 相对于ImageView的位置是固定的。

现在,您只需添加即可抑制皮棉错误

TextView

到ImageView。

最好在issue tracker

下进行报告
tools:ignore="MissingConstraints"

使用Parcelize时,实际上发生了类似的事情(毛发错误),据报告here