めも。サンプルコードなのでアレ。
■TextView
テキストを表示する場合は以下のようにする。
<TextView android:id="@+id/list_face" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="17sp" android:textColor="#333333" />
■EditText
以下のようにして編集可能なテキスト領域を設置する。
<EditText android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="top" android:id="@+id/edit_text"/>
デフォルトでは水平方向でセンタリングされるのでgravityを指定し変更する。
■AutoCompleteTextView
以下のように入力補助付きのテキストエリアを生成できる。
<AutoCompleteTextView android:id="@+id/autocomp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:completionThreshold="2" />
但し、これだけでは完結しない。
候補表示用レイアウトファイル
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > </TextView>
プログラム
以下のようにして入力候補をセットする。
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.text, new String[]{"hoge", "fuga", "piyo"}); ((AutoCompleteTextView) findViewById(R.id.autocomp)).setAdapter(adapter);
■ImageView
画像表示用View。
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" android:id="@+id/icon" />
■VideoView
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:id="@+id/movie" />
以下のようにして動画ソースをセットする。
((VideoView) findViewById(R.id.movie)).setVideoPath("/data/adult.mp4");
■Button
以下のようにしてボタンを設置することができる。
<Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/app_name" />
以下のようにしてクリックした時のイベントを定義する。
((Button) findViewById(R.id.button)).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } });