Chain이란?

constraint_layout에서 뷰들을 연결시켜 배치 하는 것입니다. 연결된 View들은 chain 속성에 따라서

여백을 조절하거나 LinearLayout처럼 특정 View의 Weight를 조절 할 수도 있습니다.

Chain Style

chain의 style은 총 세가지가 있습니다.

app:layout_constraintHorizontal_chainStyle=””
app:layout_constraintVertical_chainStyle=””

과 같은 형식으로 지정 가능합니다.

  • spread (Default)

기본값이며, View들간 공백을 균등하게 배분합니다.

  • spread_inside

View들간 공백을 균등하게 배분하되, 가장 첫번째, 마지막 View를 각각 부모와 여백이 없도록 밀착 시킨 후 배분합니다.

  • packed

Chaining된 View들 간 뭉치게 됩니다.

 

Weighted

Linearlayout에서도 활용 되었던 부분으로 Chainig된 View들은 0dp(match constraints)로 설정됩니다. 공간에 View들의 균등하게 배분되며

layout_constraintHorizontal_weight 혹은 layout_constraintVertical_weight 를 통해서 특정 View의 크기를 조절 할 수 있습니다.

 

 

이미지 출처

https://constraintlayout.com/basics/create_chains.html

 

ConstraintLayout

Chains v2.4 alpha 7 All of the examples in this article have been created using Android Studio v2.4 alpha 7. You may see differences if you are using a different version. v1.1+ All of the examples in this article have been created using ConstraintLayout v1

constraintlayout.com

 

+ Recent posts