AndroidレイアウトのリニアレイアウトLinearLayout
12434 ワード
一、LinearLayout概要:
LinearLayoutは、横方向または縦方向に配列されたサブコントロールを含む線形レイアウトコントロールです.
二、LinearLayout属性:
1、android:orientation = ""
このプロパティは、他のサブクラスコントロールの配置方法(vertical:垂直;horizontal:水平)を決定します.
2、android:gravity = ""
この属性は彼のすべてのサブクラスのxyの位置を決定し、複数の属性は一緒に(android:gravity="bottom|right")、よく使われるいくつかの属性値を使用することができます.
center_vertical:垂直(Y中心)
center_horizontal:水平(X引き中)
センター:水平垂直方向中央
right:サブクラスコントロールは現在のレイアウトの右側にあります
left:サブクラスコントロールは現在のレイアウトの左側にあります
bottom:サブクラスコントロールは現在のレイアウトの下にあります
3、サブクラスコントロールがLinearLayoutでよく使う属性
android:layout_gravity=「bottom」------現在の親コンテナのXYの位置を指し、この属性に注意する点:
この属性の属性値はandroid:gravity=""と同じです
このプロパティが目的の効果に達しない場合は、レイアウトのandroid:gravity=""で制御します.
線形レイアウトのandroid:orientation=「vertical」プロパティと組み合わせて使用する必要があります.このプロパティの値によって効果が異なります.
android:layout_Weight="1"----現在の親コンテナに対するコントロールの割合
三、レイアウトのネスト
レイアウト間はネストできます.1つのレイアウトに1つ以上のレイアウトを追加できます(任意のレイアウトでも可能ですが、線形レイアウトでも相対レイアウトをネストできます).
LinearLayoutは、横方向または縦方向に配列されたサブコントロールを含む線形レイアウトコントロールです.
二、LinearLayout属性:
1、android:orientation = ""
このプロパティは、他のサブクラスコントロールの配置方法(vertical:垂直;horizontal:水平)を決定します.
2、android:gravity = ""
この属性は彼のすべてのサブクラスのxyの位置を決定し、複数の属性は一緒に(android:gravity="bottom|right")、よく使われるいくつかの属性値を使用することができます.
center_vertical:垂直(Y中心)
center_horizontal:水平(X引き中)
センター:水平垂直方向中央
right:サブクラスコントロールは現在のレイアウトの右側にあります
left:サブクラスコントロールは現在のレイアウトの左側にあります
bottom:サブクラスコントロールは現在のレイアウトの下にあります
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="bottom|right" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
3、サブクラスコントロールがLinearLayoutでよく使う属性
android:layout_gravity=「bottom」------現在の親コンテナのXYの位置を指し、この属性に注意する点:
この属性の属性値はandroid:gravity=""と同じです
このプロパティが目的の効果に達しない場合は、レイアウトのandroid:gravity=""で制御します.
線形レイアウトのandroid:orientation=「vertical」プロパティと組み合わせて使用する必要があります.このプロパティの値によって効果が異なります.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:layout_gravity="center_horizontal"
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
android:layout_Weight="1"----現在の親コンテナに対するコントロールの割合
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
三、レイアウトのネスト
レイアウト間はネストできます.1つのレイアウトに1つ以上のレイアウトを追加できます(任意のレイアウトでも可能ですが、線形レイアウトでも相対レイアウトをネストできます).
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="2" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>