Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mochico/b52e5d3d5d967dc48200f488dde1248f to your computer and use it in GitHub Desktop.
Save mochico/b52e5d3d5d967dc48200f488dde1248f to your computer and use it in GitHub Desktop.
Sample for guideline and percent in 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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff">
<android.support.constraint.Guideline
android:id="@+id/vertical_center_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintGuide_percent="0.5"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="タイトル"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/vertical_center_guideline"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="YYYY年MM月dd日"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="@id/image_view"
app:layout_constraintEnd_toStartOf="@id/vertical_center_guideline"/>
<ImageView
android:id="@+id/image_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#999"
app:layout_constraintDimensionRatio="h,8:5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/vertical_center_guideline" />
</android.support.constraint.ConstraintLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment