LoginSignup
0
0

More than 1 year has passed since last update.

【Kotlin研修3日目】ConstraintLayoutの制約とチェイン機能

Posted at

ConstraintLayout

参考: 研修1日目
Android Studio標準のレイアウト部品(ビューグループ)
ビュー(ウィジェット)相対的配置を可能にするレイアウト。

RelativeLayoutは、任意ビューを基点とし、基点を基にした相対配置を行う。
ConstrainLayoutは、全てビューを相対指定して配置を行う。

制約(Constraint)

ビューx/y方向に存在するビュー(親ビューも指定可能)の指定。
制約は、x/y方向に対して1つ以上ビューを指定する。

制約の属性(attribute)

属性 内容
app:layout_constraintTop_toTopOf 方向のビュー
親部品: parent
それ以外: ビューのid
app:layout_constraintTop_toBottomOf 方向のビュー
親部品: parent
それ以外: ビューのid
app:layout_constraintStart_toStartOf 方向のビュー
親部品: parent
それ以外: ビューのid
app:layout_constraintEnd_toEndOf 方向のビュー
親部品: parent
それ以外: ビューのid

ConstraintLayoutにおけるlayout_width/height

親ビューの上限サイズまで拡張する場合は、layout_width/height属性に0dpを指定する(=Match Constraints)。
または、DesignモードのConstraint Widgetアイコンで変更することができる。
ConstraintLayoutではmatch_parentが使用不可

3種類のlayout_width/height

アイコン(属性値) 内容
WrapContent.png Wrap Content
ビューの表示に必要な最小サイズ
Fixed.png Fixed
具体的なサイズ単位
MatchConstraints.png Match Constraints
制約内での最大サイズ
※設定値: 0dp

ベースライン

ビュー間で、文字列の位置を制約できる線。

ガイドライン

ビュー間で、ビューの位置を制約できる線。

チェイン機能

互いに制約し合う、複数のビューのグループ化。

チェインスタイル(chain style)

スタイル 内容
spread 均等配置
spread inside 親レイアウト境界に対して、
両端ビューが接する均等配置
packed 各ビューが接する配置
weighted spread/spread inside配置のうち、
Match Constraintsを適用した配置
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0