FrameLayoutの利用

FrameLayoutの利用

FrameLayoutは、Viewを重ねて表示するのに使う 

使うには、レイアウトファイルで設定する

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
38
39
40
41
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
 
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:layout_margin="@dimen/padding_medium"
android:alpha="0.8"
android:background="@color/FlatLightCyan"
android:gravity="center"
android:padding="@dimen/layout_common_size_large"
android:text="View01"
android:textColor="@android:color/white"/>
 
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/padding_medium"
android:alpha="0.8"
android:background="@color/FlatLightYellow"
android:gravity="center"
android:padding="@dimen/layout_common_size_large"
android:text="view02"
android:textColor="@android:color/white"/>
 
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_margin="@dimen/padding_medium"
android:alpha="0.8"
android:background="@color/FlatLightRed"
android:gravity="center"
android:padding="@dimen/layout_common_size_large"
android:text="view03"
android:textColor="@android:color/white"/>
[/FrameLayout]

ただし、FrameLayoutは、Viewは重ねられるけど
Viewそのものに対する配置指定だけで
関連する配置の指定ができない

このため、ほとんどの場合
RelativeLayoutを使うことで
Viewの配置指定や重なりの表現をすることになる

FrameLayoutの使い道としては
カメラアプリとか
ゲームのタイトル画面など
レイアウトがシンプルだけど
画像を重ねる必要がある場合とか
Fragmentの器にするなどの使い方をする

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です