Android 代码里设置ImageView的src和background

xiaoxiao2021-02-27  312

设置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)); 不要把两者用法混淆了 否则图片就走样了

转载请注明原文地址: https://www.6miu.com/read-3937.html

最新回复(0)