よく使うUIパーツのプロパティ

[参考記事] Androidのlayoutで使用できるパーツの一覧 ビュー(部品)

android:textColor

文字の色を指定します。

android:textColor="#00FF00"

android:textSize

文字のサイズを指定します。

android:textSize="12px"

android:textStyle

文字のスタイルを指定します。

android:textStyle="bold"

android:background

背景色を指定します。

android:background="#ff0000"

android:layout_width android:layout_height

オブジェクトの高さや幅を指定します。
wrap_contentとfill_parentの違い

Android2.2からmatch_parentが追加されましたが、この値がlayoutに記載されていると、2.1で動作しなくなります。

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="100px"
android:layout_height="100px"

android:layout_width="match_parent"
android:layout_height="match_parent"

android:maxWidth android:maxHeight

オブジェクトの最大の高さや幅を指定します。

android:maxWidth="100px"
android:maxHeight="100px"

android:maxLength

オブジェクトの最大の長さ(文字数)を指定します。

android:maxLength="10"

android:maxLines

オブジェクトの最大の行数を指定します。

android:maxLines="4"

android:padding

パディングを指定します。

android:padding="5px 5px 5px 5px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:paddingLeft="10px"
android:paddingRight="10px"

android:layout_margin

マージンを指定します。

android:layout_margin="5px"
android:layout_marginTop="10px"
android:layout_marginBottom="10px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"

android:layout_gravity

オブジェクトの配置方法を指定します。

android:layout_gravity="right"
指定値動作
topコンテナの上部に配置し、サイズ変更は行いません。
bottomコンテナの下部に配置し、サイズ変更は行いません。
leftコンテナの左側に配置し、サイズ変更は行いません。
rightコンテナの右側に配置し、サイズ変更は行いません。
center_vertical上下中央に配置し、サイズ変更は行いません。
fill_verticalオブジェクトの高さを、コンテナのサイズに合わせます。
center_horizontal左右中央に配置し、サイズ変更は行いません。
fill_horizontalオブジェクトの幅を、コンテナのサイズに合わせます。
center上下左右中央に配置し、サイズ変更は行いません。
fillオブジェクトの高さ・幅を、コンテナのサイズに合わせます。
clip_verticaltop/bottomの追加オプションとして、オブジェクトの上部/下部の境界をコンテナの境界に合わせます。
clip_horizontalleft/rightの追加オプションとして、オブジェクトの左側/右側の境界をコンテナの境界に合わせます。

関連記事

スポンサーリンク

{eval}関数 変数をテンプレートとして扱う

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る