Created
August 27, 2016 08:04
-
-
Save writtmeyer/f5971266394b2316eb01b566cdeff2a0 to your computer and use it in GitHub Desktop.
Align one view's edge to another view's center in Android's ConstraintLayout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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