TIL: Guideline

yxnsx·2021년 8월 2일
0

TIL: Things I Learned

목록 보기
4/4
post-thumbnail

Period

  • 2021-08-02(월) ~ 2021-08-08(일)


Things I Learned

1️⃣ Guideline

Guideline이란?

  • ConstraintLayout에 대한 가이드라인 헬퍼 객체를 나타내는 유틸리티 클래스
  • 헬퍼 객체는 View.GONE으로 표시되어 디바이스에 나타나지 않음
  • 레이아웃 목적으로만 사용되며 ConstraintLayout 내에서만 동작함
  • 가이드라인은 수평 또는 수직으로 배치할 수 있음
  • xml 파일에서 직접 작성하거나 xml 파일 Design 탭의 Palette에서 Guideline을 드래그 앤 드롭해서 사용할 수 있음


Guideline 위치 지정

  • 가이드라인의 위치 지정은 세 가지 방법으로 가능함
    1. 레이아웃의 왼쪽 또는 상단에서 고정 거리 지정
      layout_constraintGuide_begin
    2. 레이아웃의 오른쪽 또는 아래쪽에서 고정 거리 지정
      layout_constraintGuide_end
    3. 레이아웃의 너비 또는 높이에 대해 백분율 지정
      layout_constraintGuide_percent

Guideline 사용 예시

<androidx.constraintlayout.widget.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">

    <androidx.constraintlayout.widget.Guideline
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/guideline"
            app:layout_constraintGuide_begin="100dp"
            android:orientation="vertical"/>

    <Button
            android:text="Button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/button"
            app:layout_constraintLeft_toLeftOf="@+id/guideline"
            android:layout_marginTop="16dp"
            app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

0개의 댓글