ウィジェットとはボタンやテキスト入力欄のような、画面を構成する要素のことです。
ウィジェットはViewクラスを継承したクラスを使用し、Layoutリソースとして定義します。
Eclipseを使用すれば、ウィジェットを視覚的に作成できます。結果はLayoutリソースとして、コードが自動生成されます。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("TEST");
// LinearLayoutを生成する
LinearLayout li = new LinearLayout(this);
li.addView(tv);
setContentView(li);
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = new TextView(this);
tv.setText("TEST");
// 既存のLinearLayoutを取得する
LinearLayout li = (LinearLayout)findViewById(R.id.layout);
li.addView(tv);
}
表示イメージ | ウィジェット | 説明 |
---|---|---|
![]() |
![]() |
|
![]() |
![]() |
プッシュボタン |
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |