6

I am playing around with the circular positioning provided by ConstraintLayout. In the below sample app I have a TextView centered on the screen and an ImageView circularly constrained to the TextView with a radius of 50dps and an angle of 45 degrees. It should be fully constrained as there are no more XML attributes starting with app:layout_constraintCircle, so I assume I have fully declared its intended position. However, Android Studio gives me the following warning on the ImageView:

This view is not constrained. It only has designtime positions, so it will jump to (0,0) at runtime unless you add the constraints

Running the application proves me right as the constrained view is in its correct location and does not jump to the start of the layout.

So my question is: am I missing any additional constraints or is Android Studio somehow bugged not recognizing circular constraining as valid?

Example XML layout:

<?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>
0

1 Answer 1

4

Having tried this myself I could just say this is bug with android studio lint.

Since there is angle and radius defined ImageView's position relative to the TextView is fixed.

For now you could just suppress the lint error by adding

tools:ignore="MissingConstraints"

to the ImageView.

Better to report this in issue tracker, under

Android Public Tracker > App Development > Android Studio > Lint

Actually something similar (lint error) occurred to me when using Parcelize, which is reported here.

1
  • So it is indeed a bug. I will submit a report soon, thanks for the link. Aug 29, 2019 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.