packagecom.ex01_02;importandroid.app.Activity;importandroid.os.Bundle;importandroid.widget.ImageView;publicclassMainActivityextendsActivity{/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);//创建ImageView对象并实例化ImageView img =newImageView(this);//ImageView对象设置引用图片资源
img.setImageResource(R.drawable.flower);setContentView(img);}}