Android published ConstraintLayout 1.1.0 on the google maven repository. One of the more interesting additions to this release is Circular Positioning. Circular positioning allows you to constrain a widget center relative to another widget center, at an angle and a distance. This allows you to position a widget on a circle.

ConstraintLayout Circular constraints

Add ConstraintLayout to your project


To use ConstraintLayout in your project, proceed as follows: 1.Ensure you have the maven.google.com repository declared in your project-level build.gradle file:

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

2.Add the library as a dependency in the same build.gradle file:

dependencies {
    ....
    compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
}

Example Circular positioning


<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    ...
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <Button
        android:id="@+id/buttonA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button A"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <Button
        android:id="@+id/buttonB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button B"
        app:layout_constraintCircle="@id/buttonA"
        app:layout_constraintCircleAngle="45"
        app:layout_constraintCircleRadius="100dp"
        />
</android.support.constraint.ConstraintLayout>

The following attributes can be used:

  • layout_constraintCircle : references another widget id.
  • layout_constraintCircleRadius: the distance to the other widget center
  • layout_constraintCircleAngle : which angle the widget should be at (in degrees, from 0 to 360).

Related Post

New features in Constraint Layout 1.1.0  ]]>