Align one view's edge to another view's center in Android's ConstraintLayout
<?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" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<Button | |
android:id="@+id/target" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginStart="32dp" | |
android:text="TargetView" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
tools:ignore="HardcodedText" /> | |
<Button | |
android:id="@+id/view_to_align" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="64dp" | |
android:text="View to left align to target's center" | |
app:layout_constraintBottom_toTopOf="@+id/target" | |
app:layout_constraintLeft_toRightOf="@+id/dummy_view" | |
tools:ignore="HardcodedText" /> | |
<Button | |
android:id="@+id/dummy_view" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Dummy view" | |
android:visibility="gone" | |
app:layout_constraintLeft_toLeftOf="@+id/target" | |
app:layout_constraintRight_toRightOf="@+id/target" | |
app:layout_constraintTop_toTopOf="parent" | |
tools:ignore="HardcodedText" | |
tools:layout_editor_absoluteY="234dp" /> | |
</android.support.constraint.ConstraintLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment