以前は RelativeLayout で match_parent を使っていましたが、知らぬ間に ConstraintLayout に変更されたようです。一年以上前に XML の書き方を少しかじった程度だったので、Udacity を見ながら対応に苦戦…
ConstraintLayout
レスポンシブに対応しやすい新しいレイアウト方法に変更したようです。
ConstraintLayout | Android Developer
例えば、TextView を画面右下に配置したいとき RelativeLayout タグ内で
1 2 3 4 5 6 |
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:text="text" /> |
と書いていましたが、ConstraintLayout タグ内では
1 2 3 4 5 6 |
<TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="text" app:layout_constraintRight_toRightOf="parent" app:layout_constraintBottom_toBottomOf="parent" /> |
と書くようになりました。(たぶん)
ConstraintLayout になってから XML 名前空間に app も追加されたようです。
match_parentは使用不可
wrap_content は使えますが、match_parent は使用できなくなりました。その代わりに、match_constraint を使えと書いてありますが、そういう値があるわけではありません。
1 2 3 4 5 6 7 8 |
<TextView android:layout_height="0dp" android:layout_width="0dp" android:text="text" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintBottom_toBottomOf="parent" /> |
height と width は 0dp に指定すると、match_constraint とみなされるようです。それから、match_parent 同様画面全体にフィットさせるために、下の 4 行が必要です。
(参考)