How to make ConstraintLayout work with percentage values

Use: a guideline with app:layout_constraintGuide_percent like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.3" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello text"
        app:layout_constraintLeft_toRightOf="@id/guideline"
        app:layout_constraintRight_toRightOf="parent" />

</android.support.constraint.ConstraintLayout>

And then you can use this guideline as anchor points for other views.

Two minor but important notes:

  • TextView width should be 0dp i.e. match constraint and not match parent
  • Guideline orientation should be vertical not horizontal

References
https://stackoverflow.com/questions/42958168/constraint-layout-with-percentage-not-working-as-expected
https://stackoverflow.com/questions/37318228/how-to-make-constraintlayout-work-with-percentage-values