Last active
July 5, 2018 09:22
-
-
Save FranRiadigos/27417eaf4caa83c4e177d3715b11d50a to your computer and use it in GitHub Desktop.
Relative Guidelines with ConstraintLayouts. Helper code utilised in the article https://medium.com/@kuassivi/relative-guidelines-w-constraintlayouts-9533b3c546f3
This file contains hidden or 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
<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" | |
android:animateLayoutChanges="true"> | |
<!-- This View acts like a helper guideline | |
and anchors to the "relative_view" TextView. --> | |
<View | |
android:id="@+id/relative_guideline_1" | |
app:layout_constraintBottom_toBottomOf="@+id/relative_view" | |
app:layout_constraintVertical_bias="0.45" <-- Optional | |
android:layout_width="0dp" | |
android:layout_height="1dp" | |
android:layout_marginBottom="1dp" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
tools:background="@android:color/white" | |
android:visibility="invisible" | |
tools:visibility="visible" /> | |
<!-- This ImageView constraints its top to the guideline | |
instead of the parent. It is not vertically constraintened, | |
so it can't use bias, but it can be positioned | |
relatively to where the "relative_guideline_1" is. --> | |
<ImageView | |
android:layout_width="0dp" | |
android:layout_height="0dp" | |
android:layout_marginTop="10dp" | |
android:adjustViewBounds="true" | |
android:scaleType="fitCenter" | |
android:clickable="true" | |
android:focusable="true" | |
android:visibility="gone" | |
tools:visibility="gone" | |
app:layout_constraintDimensionRatio="h,1:1" | |
app:layout_constraintHeight_default="percent" | |
app:layout_constraintWidth_default="percent" | |
app:layout_constraintHeight_percent=".4" | |
app:layout_constraintWidth_percent=".4" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/relative_guideline_1" | |
app:srcCompat="@drawable/vector_image" /> | |
<TextView | |
android:id="@+id/relative_view" | |
android:layout_width="0dp" | |
android:layout_height="wrap_content" | |
android:background="@color/red" | |
android:padding="20dp" | |
android:visibility="gone" | |
tools:visibility="visible" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
tools:text="@string/advise_power_save_is_on" /> | |
</android.support.constraint.ConstraintLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment