view andlayout

18

Click here to load reader

Upload: yamane-toshiaki

Post on 19-May-2015

872 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: View andlayout

UI

Widget

Page 2: View andlayout

Activity の構成要素

• Activity has Views or ViewGroups

• ViewGroup has ViewGroups or Views

• ViewGroup has ViewGroups or Views

• recursive continue

Page 3: View andlayout

Layout

• View は Widget

• ViewGroup は Layout

• Layout の記述は res/layout 配下の XML

• 通常 onCreate で setContentView に渡す

Page 4: View andlayout

代表的な View

• TextView

• EditText

• ImageView

• Button

• ImageButton

Page 5: View andlayout

代表的な ViewGroup

• LinearLayout

• TableLayout

• Gallery

• TabHost

Page 6: View andlayout

参考 URL

• http://bit.ly/91DbG4

• http://bit.ly/8rBLYG

• http://bit.ly/d5ieWu

Page 7: View andlayout

View を弄くってみましょう

• ハロワ作成

• TextView を Button にしてみる

• width 属性を fill parent から wrap content に

• height 属性を wrap content から fill parent に

Page 8: View andlayout

できれば

実機でも

Page 9: View andlayout

イベント駆動 (リスナ) について

• View にリスナ i/f を実装させてイベントが拾える

• Button の例を試してみましょう

Page 10: View andlayout

Button オブジェクトの取得• 先に出てきたサンプルで試してみましょう

Button button = (Button)findViewById(R.id.button);

Page 11: View andlayout

リスナの設定• クリックしたら Toast 出力• setContentView の後で setOnClickListener

button.setOnClickListener(new OnClickListener() {

@Overridepublic void onClick(View arg0) {

Toast.makeText(ListenActivity.this,"button clicked",Toast.LENGTH_LONG).show();

}});

Page 12: View andlayout

イベントの例• クリック

• タッチ

• タップ

• その他色々– Android プログラミングはイベントの塊

Page 13: View andlayout

Dialog

• ダイアログ画面です

• View を継承していません

Page 14: View andlayout

代表的な Dialog

• AlertDialog

• DatePickerDialog

• ProgressDialog

• TimePickerDialog

• ZoomDialog

Page 15: View andlayout

Dialog のサンプル

• AlertDialog を使ってみましょう

• http://bit.ly/bghNAh

Page 16: View andlayout

オプションメニューについて

• Menu ボタンを押すことで画面上に現われる

• onCreateOptionMenu メソドを使って準備

• メニュ表示直前に呼ばれるonPrepareOptionsMenu メソド

Page 17: View andlayout

オプションメニューのサンプル

• 実装例 (http://db.tt/HNf3bu)

• 項目は何個まで増やせるでしょうか

Page 18: View andlayout

チュートリアルの紹介

• NotepadTutorial

• http://bit.ly/c8jm70