I don’t understand why you have to use complex Guideline systems when you can also just use:
app:layout_constraintWidth_percent="0.5"
for half the width of the parent and
app:layout_constraintDimensionRatio="1:1"
to reach the same height as the width.
Fyi: This aspect ratio takes all numbers and even doubles.
Here is the full code with the center:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
style="@style/parentViewStyle"
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">
<View
android:id="@+id/view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintWidth_percent="0.5"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5" />
</android.support.constraint.ConstraintLayout>
source
share