LinearLayoutのレイアウトをどのように設定しますか?
Androidでは、LinearLayoutレイアウトを設定するためにXMLを使用することができます。次に示すのは一例です:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"/>
</LinearLayout>
この例では、私たちは垂直方向のLinearLayoutレイアウトを作成し、その中に2つのボタンを含めました。LinearLayoutの方向(縦または横)を指定するにはandroid:orientation属性を設定し、レイアウトの幅と高さを決定するにはandroid:layout_widthとandroid:layout_height属性を設定します。子要素のサイズを決定するには、子要素のandroid:layout_widthとandroid:layout_height属性を設定します。