UIコンポーネント/LinearLayout

Last-modified: 2012-09-30 (日) 01:42:44

android.widget.LinearLayout

リファレンス:http://developer.android.com/reference/android/widget/LinearLayout.html

SUMMARY

継承するXML属性
android.view.Viewの属性を継承します。
android.view.ViewGroupの属性を継承します。
 
XML属性
属性対応メソッド概要
android:baselineAlignedsetBaselineAligned(boolean)ベースラインに合わせて配置するかどうかを指定します。
android:baselineAlignedChildIndexsetBaselineAlignedChildIndex(int)ベースラインとなる属性を持ったWidgetのインデックスを指定します。
android:gravitysetGravity(int)オブジェクトの配置方法を指定します。
android:orientationsetOrientation(int)配置する向きを指定します。
 

XML属性

  • android:baselineAligned
     
    レイアウト内の各Widgetのベースラインに合わせて配置するかどうかを指定します。
    指定値デフォルト動作
    trueレイアウト内の各Widgetのベースラインに合わせて配置します。
    falseレイアウト内の各Widgetのベースラインに合わせて配置しません。
     
    このタイプの値を含めている他のリソース、テーマ属性の参照を指定します。
     
    • サンプルコード
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:id="@+id/TestSample"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:baselineAligned="true"
                  android:orientation="horizontal">
          <TextView android:id="@+id/Text1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="name"> </TextView>
          <EditText android:id="@+id/EText1"
                    android:layout_height="wrap_content"
                    android:layout_width="fill_parent"/>
      </LinearLayout>
       
      結果
      baselineAligned1.PNG
       

  • android:baselineAlignedChildIndex
     
    レイアウト内のベースラインとなる属性を持ったWidgetがどこにあるのか、
    追加した順番のインデックスで指定します。
     
    このタイプの値を含めている他のリソース、テーマ属性の参照を指定します。
     
    • サンプルコード
      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="horizontal"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:baselineAligned="true">
          <TextView
                  android:layout_height="40dip"
                  android:layout_width="wrap_content"
                  android:text="text"/>
          <EditText
                  android:layout_height="50dip"
                  android:layout_width="wrap_content"/>
          <Button
                  android:layout_height="60dip"
                  android:layout_width="wrap_content"
                  android:text="Bu"/>
          <LinearLayout
                  android:baselineAlignedChildIndex="2"
                  android:orientation="vertical"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent">
              <TextView
                  android:layout_height="30dip"
                  android:layout_width="wrap_content"
                  android:text="text2"/>
              <EditText
                  android:layout_height="60dip"
                  android:layout_width="wrap_content"/>
              <Button
                  android:layout_height="90dip"
                  android:layout_width="wrap_content"
                  android:text="Bu2"/>
          </LinearLayout>
      </LinearLayout>
       
      結果
      baseline.PNG
       

  • android:gravity
     
    オブジェクトの配置方法を指定します。
    "|"で区切って複数指定することが可能です。
    指定値デフォルト動作
    topコンテナの上部に配置し、サイズ変更は行いません。
    bottomコンテナの下部に配置し、サイズ変更は行いません。
    leftコンテナの左側に配置し、サイズ変更は行いません。
    rightコンテナの右側に配置し、サイズ変更は行いません。
    center_vertical上下中央に配置し、サイズ変更は行いません。
    fill_verticalオブジェクトの高さを、コンテナのサイズに合わせます。
    center_horizontal左右中央に配置し、サイズ変更は行いません。
    fill_horizontalオブジェクトの幅を、コンテナのサイズに合わせます。
    center上下左右中央に配置し、サイズ変更は行いません。
    fillオブジェクトの高さ・幅を、コンテナのサイズに合わせます。
    clip_verticaltop/bottomの追加オプションとして、オブジェクトの上部/下部の境界をコンテナの境界に合わせます。
    clip_horizontalleft/rightの追加オプションとして、オブジェクトの左側/右側の境界をコンテナの境界に合わせます。
     
    gravity.PNG
     

  • android:orientation
     
    配置する向きを指定します。
    指定値デフォルト動作
    horizontal水平方向に並べます。
    vertical垂直方向に並べます。
     
    android_orientation1.PNG
     

  • android:orientationのデフォルト値はhorizontalです。Eclipse3.6にてorientation属性を抜いたところ、horizontalの動作をいたしました -- 2011-06-29 (水) 14:57:04