※前提条件:本情報はAndroid Studio 1.5.1を基づいて説明してる layout_weight によるレイアウトの重み付け <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <View android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#ff0000"/> <View android:layout_width="0dp" android:layout_height="50dp" android:layout_weight="1" android:background="#00ff00"/> </LinearLayout> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="2" android:text="hoge"/> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="5" android:text="fuga"/> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:text="hage"/> </LinearLayout> LinearLayout でやると一度に横方向若しくは縦方向の均等配置しかできない。 「画面いっぱいに表示されるカレンダー UI」を作りたいとしよう。 曜日のぶんだけ横に均等配置。そして表示に必要なぶん (6 行ぶん) 縦にも均等配置。 愚直にやろうとすると以下のように LinearLayout を入れ子にすることになってしまう: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <View android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> </LinearLayout> ... (あと 5 回同じものが続く) </LinearLayout> あなたのお住まいの地域で最安のブロードバンド選び コメント: |