第一种在xml布局文件中添加(静态的添加)
<ImageView
android:id="@+id/image_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/me"
></ImageView>
就像在html标签中
image
android:src引用的图片的路径!
在res建立drawable文件夹其中的me为文件的名字。
第二中(动态的添加)
在Activity中动态的添加
例如当点击按钮时 显示图片
public class Framemain extends Activity {
private ImageView imageView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.framemain);
Intent intent=this.getIntent();
TextView textView=(TextView)findViewById(R.id.showUser);
textView.setText(intent.getStringExtra("username"));
imageView=(ImageView) findViewById(R.id.me_image);
Resources resources=getResources();
Drawable drawable =resources.getDrawable(R.drawable.me);
imageView.setImageDrawable(drawable);
}
}
}