view andlayout
TRANSCRIPT
UI
Widget
Activity の構成要素
• Activity has Views or ViewGroups
• ViewGroup has ViewGroups or Views
• ViewGroup has ViewGroups or Views
• recursive continue
Layout
• View は Widget
• ViewGroup は Layout
• Layout の記述は res/layout 配下の XML
• 通常 onCreate で setContentView に渡す
代表的な View
• TextView
• EditText
• ImageView
• Button
• ImageButton
代表的な ViewGroup
• LinearLayout
• TableLayout
• Gallery
• TabHost
参考 URL
• http://bit.ly/91DbG4
• http://bit.ly/8rBLYG
• http://bit.ly/d5ieWu
View を弄くってみましょう
• ハロワ作成
• TextView を Button にしてみる
• width 属性を fill parent から wrap content に
• height 属性を wrap content から fill parent に
できれば
実機でも
イベント駆動 (リスナ) について
• View にリスナ i/f を実装させてイベントが拾える
• Button の例を試してみましょう
Button オブジェクトの取得• 先に出てきたサンプルで試してみましょう
Button button = (Button)findViewById(R.id.button);
リスナの設定• クリックしたら Toast 出力• setContentView の後で setOnClickListener
button.setOnClickListener(new OnClickListener() {
@Overridepublic void onClick(View arg0) {
Toast.makeText(ListenActivity.this,"button clicked",Toast.LENGTH_LONG).show();
}});
イベントの例• クリック
• タッチ
• タップ
• その他色々– Android プログラミングはイベントの塊
Dialog
• ダイアログ画面です
• View を継承していません
代表的な Dialog
• AlertDialog
• DatePickerDialog
• ProgressDialog
• TimePickerDialog
• ZoomDialog
Dialog のサンプル
• AlertDialog を使ってみましょう
• http://bit.ly/bghNAh
オプションメニューについて
• Menu ボタンを押すことで画面上に現われる
• onCreateOptionMenu メソドを使って準備
• メニュ表示直前に呼ばれるonPrepareOptionsMenu メソド
オプションメニューのサンプル
• 実装例 (http://db.tt/HNf3bu)
• 項目は何個まで増やせるでしょうか
チュートリアルの紹介
• NotepadTutorial
• http://bit.ly/c8jm70