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)

上一篇:【原创】Java基础之简单修改jar包中的class


下一篇:[js开源组件开发]数字或金额千分位格式化组件