facebook twitter hatena line email

Android/レイアウト/Layoutなどの使い方

提供: 初心者エンジニアの簡易メモ
2019年5月21日 (火) 14:46時点におけるAdmin (トーク | 投稿記録)による版 (Admin がページ「Android/レイアウト/LinearLayoutなどの使い方」を「Android/レイアウト/Layoutなどの使い方」に、リダイレクトを残さずに移動しました)

移動: 案内検索

レイアウト種類

  • LinearLayout ・・レイアウトを横に並べる
  • FrameLayout ・・レイアウトを重ねる
  • RelativeLayout ・・上の2つの組み合わせを同時にできる

水平一直線

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="horizontal"
   >

垂直一直線

<LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical"
   >

絶対位置を指定

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"


Linearでの配置

android:gravity="right"
android:gravity=”bottom”
top  コンテナの上部に配置
bottom  コンテナの下部に配置
right  コンテナの左側に配置
left  コンテナの右側に配置
fill  オブジェクトの高さ・幅を、コンテナのサイズに合わせる。
fill_vertical  オブジェクトの高さをコンテナのサイズに合わせる。
fill_horizontal  オブジェクトの幅をコンテナのサイズに合わせる。
center  オブジェクトを中央に配置する。サイズ変更無し。
center_vertical  オブジェクトを上下中央に配置しする。サイズ変更無し。
center_horizontal  オブジェクトを左右中央に配置する。サイズ変更無し。
clip_vertical  top/bottomの追加オプションとして、オブジェクトの上部/下部の境界をコンテナの境界に合わせます。
clip_horizontal  left/rightの追加オプションとして、オブジェクトの左側/右側の境界をコンテナの境界に合わせま

す。


ConstraintLayout

Android Studio 2.2 previewよりConstraintLayoutが追加された

https://qiita.com/tomoima525/items/0584be581a0d3a4db8c5

参考

http://d.hatena.ne.jp/Korsakov/20110131/1296504108