IT/Android

[Layout]Constraint Layout

GeunChoi 2021. 2. 22. 12:31
728x90

Constraint 세 가지 모드

  1. Wrap Content : 위젯 안쪽의 내용물(주로 텍스트)에 크기를 맞춤
  2. Fixed : 가로세로 속성 필드에 입력된 크기에 맞게 가로세로를 고정
  3. Match Constraint : 크기를 제약 조건인 Constraint 연결부에 맞춤

 

1. Wrap Content

<Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

width = wrap_content

 

2. Fixed

    <Button
        android:id="@+id/button2"
        android:layout_width="88dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

width = 88dp 고정

 

 

 

3. Match Constraint

    <Button
        android:id="@+id/button2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="44dp"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />

width = 0dp

 

 

http://developer.android.com/training/constraint-layout