Android 代码里设置ImageView的src和background

设置ImageView的src:

image.setImageDrawable(getResources().getDrawable(R.drawable.blackk));
String path=Environment.getExternalStorageDirectory()+File.separator+”test.jpg”;
Bitmap bm = BitmapFactory.decodeFile(path);
image.setImageBitmap(bm);
image.setImageResource(R.drawable.blackk);

设置ImageView的background:  

image.setBackground(getResources().getDrawable(R.drawable.blackk));
image.setBackgroundResource(R.drawable.blackk);
image.setBackgroundDrawable(getResources().getDrawable(R.drawable.blackk));

不要把两者用法混淆了 否则图片就走样了

你可能感兴趣的:(Android)