The UI of application can be set by the combination of View and ViewGroup.
・The set of Veiw is ViewGroup.
・ViewGroup contains two or more View.
・ViewGroup can be contained in ViewGroup.
・The layout inherit ViewGroup.
※Refer to the following succession charts for the practical visualization.
ViewGroup and the succession relation are described as follows.
Typical View-Groups (layouts) are described as follows.
Ⅰ | Absolute layout | The layout placement which specifies the absolute coordinate. |
Ⅱ | Relative layout | The layout placement which specifies the relative coordinate. |
Ⅲ | Linear layout | 縦/横 指定の配置が可能 |
Ⅳ | Table layout | The table form can be arranged. |
Ⅴ | Frame layout | Overlapping the VIEW is possible. |
他色々 |
・部品の配置を 【absolute coordinate】 で指定するLayout。
・SDK1.5から非推奨となった。(恐らく画面サイズの異なる複数のデバイスに対応できない為)
layout_x
layout_y
layout_width
layout_height
fill_parentは最大サイズ。wrap_contentは最小サイズ
相対的な位置指定をするレイアウト。また,上端や下端にレイアウトするといった指定を行うことも可能
「基準の位置を変更すれば、それに伴いほかのウィジェットも自動的に位置が調整できる」「斜めや円形にも配置が可能」というメリットがある一方、
「気軽にウィジェットを追加・削除できない」、「どのようにリレーションさせているか分からなくなってしまう」という点がデメリット。
Liner Layoutは、縦向きまたは横向きに一直線にウィジェットを並べるレイアウト
表形式に並べるレイアウト
Outline 画面
参考:ボタンのレイアウト
http://www.javadrive.jp/android/xml_layout/index7.html
参考:画面の作り方
http://www.techfirm.co.jp/lab/android/view.html
参考:Android Developer
http://www.techdoctranslator.com/android/guide/ui/declaring-layout
Frame Layoutは、Viewを重ねる時に利用しやすいレイアウト
例えば、画像を重ねる際に利用できる。
Outline 画面
半分半分にするときは、LinearLayoutを用いてlayout_widthを0にして、weightを1とする
Example of layout.xml
<LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:layout_width="0dip" android:layout_weight="1" android:text="前へ" android:id="@+id/Button01" android:layout_height="wrap_content" > </Button> <Button android:layout_width="0dip" android:layout_weight="1" android:text="次へ" android:id="@+id/Button02" android:layout_height="wrap_content" android:layout_alignParentRight="true"> </Button> </LinearLayout>
・nextFoxusDown - フォーカスが下方向に遷移した時の遷移先Viewを定義
・padding - 上下左右のパディングを設定
・scrollbarAlwaysDrawVerticalTrack - スクロールバーを表示するかどうか
Unit that can be used by layout
px | pixel |
dp | 密度非依存ピクセル |
sp | 倍率非依存ピクセル |
mm | millimeter |
pt | ポイント数 |
in | インチ |
横向き画面には、"Layout-land"用フォルダを用意する。