Android教程:ImageView 设置图片


Android doc中是这样描述的:

 

public void setImageResource (int resId)

这是其中的一个方法,参数resld是这样:

ImageView.setImageResource(R.drawable.icon); 

看下面这段话

Sets a drawable as the content of this ImageView.

This does Bitmap reading and decoding on the UI thread, which can cause a latency hiccup. If that's a concern, consider usingsetImageDrawable(Drawable) or setImageBitmap(Bitmap) and BitmapFactory instead.

此函数使用UI线程,可以用下面3种替代:

ImageView iv; 

String fileName = "/data/data/com.test/aa.png; 
Bitmap bm = BitmapFactory.decodeFile(fileName); 
iv.setImageBitmap(bm); 


ImageView iv = new ImageView(context); 
iv.setImageResource(iv[position]); 
iv.setScaleType(ImageView.ScaleType.FIT_XY); 
iv.setLayoutParams(new Gallery.LayoutParams(136,88)); 


mImageView = (ImageView)this.findViewById(R.id.myImageView1); 
mImageView.setImageDrawable(getResources().getDrawable(R.drawable.right)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM