レイアウトの入れ子を整列させる
内容
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="あ"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="い"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="う"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="え"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="お"
android:textSize="25sp" />
</LinearLayout>
部品の役割について
<LinearLayout>
LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
必要に応じて自身のレイアウトの縦サイズを変更する
android:layout_width="wrap_content"
必要に応じて自身のレイアウトの横サイズを変更する
android:orientation="horizontal"
属性値の方向へ子部品たちを整列させる今回の場合は横
属性値 | 整列方向 |
---|---|
horizontal | 横 |
vertical | 縦 |
<TextView>
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="あ"
android:textSize="25sp"
android:textAlignment="center"
文字の寄せる方向
左寄せ | 中央 | 右寄せ |
---|---|---|
viewStart | center | viewEnd |
↑ 右寄せ左寄せとかはtextStart/Endとかでもよいみたい
言語対応がどうとか自分は分かりません
android:background="#ffff00"
背景色を指定する。
#の左から1,2番目R(赤) 3,4番目G(緑) 5,6番目B(青)
RGBの三色それぞれに00~ffの数値を指定しています。
数値が大きくなればなるほどその色が濃くなり、0だと無し
今回の場合は数値にすると赤255,緑255,青 0,となり黄色になります。
応用
横並びを縦に
LinearLayoutを変更
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:orientation="vertical" //horizontalからverticalへ変更
各文字の間に空白を作る
TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAlignment="center"
android:background="#ffff00"
android:text="あ"
android:layout_margin="10dp"//追加
android:textSize="25sp"
それぞれのTextViewタグへ
android:layout_margin="10dp"を追加
これによって上下左右に10dp分の隙間ができる
こうなる