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