Dimension constraints

These constraints concern the sizes of widgets placed in a layout. Dimension constraints can be set on widgets, and using a ConstraintLayout:

A dimension constraint

The dimensions of a widget can be specified by the use of android:layout_width and android:layout_height:

<TextView android:layout_height="16dp" android:layout_width="32dp"/>

In a number of cases, you may want a widget to have the same dimension as its parent view group. This can be done by assigning the match_parent value to the dimension attribute:

<LinearLayout android:layout_width="120dp" android:layout_height="100dp"> <TextView  android:layout_width="match_parent" ...

Get Kotlin Programming By Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.