UIコンポーネント/LinearLayout.LayoutParams

Last-modified: 2010-12-02 (木) 01:17:44

android.widget.LinearLayout.LayoutParams

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

SUMMARY

継承するXML属性
android.view.ViewGroup.LayoutParamsの属性を継承します。
android.view.ViewGroup.MarginLayoutParamsの属性を継承します。
 
XML属性
属性対応メソッド概要
android:layout_gravity-オブジェクトの配置方法を指定します。
android:android:layout_weight-オブジェクトを配置する際に占める比率を、重量として指定します。
 

XML属性

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

  • android:layout_weight
     
    オブジェクトを配置する際に占める比率を、重量として指定します。
    • サンプルコード
      <?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="wrap_content"
              android:orientation="horizontal">
              <TextView android:id="@+id/Text1"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                 android:text="paramTest"> </TextView>
                 <EditText android:id="@+id/EText1"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"/>
      </LinearLayout>
       
      結果
      layout_weight1.PNG