RelativeLayoutについて
RelativeLayoutは、Viewを相対的に配置するのに使う
サンプルアプリではよく使われる
レイアウトはXMLファイルで作成する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | < RelativeLayout android:layout_width = "match_parent" android:layout_height = "match_parent" > < TextView android:layout_width = "@dimen/layout_common_size_xlarge" android:layout_height = "@dimen/layout_common_size_xlarge" android:layout_alignParentLeft = "true" android:layout_alignParentTop = "true" android:background = "@color/FlatLightCyan" android:gravity = "center" android:text = "view01" android:textColor = "@android:color/white" /> < TextView android:layout_width = "@dimen/layout_common_size_xlarge" android:layout_height = "@dimen/layout_common_size_xlarge" android:layout_alignParentRight = "true" android:layout_alignParentTop = "true" android:layout_gravity = "center" android:background = "@color/FlatLightYellow" android:gravity = "center" android:text = "view02" android:textColor = "@android:color/white" /> < TextView android:layout_width = "@dimen/layout_common_size_xlarge" android:layout_common_size_xlarge android:layout_alignParentBottom = "true" android:layout_alignParentLeft = "true" android:background = "@color/FlatLightRed" android:gravity = "center" android:text = "view03" android:textColor = "@android:color/white" /> </ RelativeLayout > |
RelativeLayoutは、属性がたくさんあって覚えにくいけど
なれるとLinearLayoutなどの複雑構造を使わずに記述できるのがメリット