@Override
public Object instantiateItem(View view, int position) {
View mv = mListViews.get(position);
((ViewPager) view).addView(mv, 0);
// 加載圖片
ImageView iv = (ImageView) mv.findViewById(R.id.imageView);
try {//圖片的名稱
String name=DBManager.getInstance(context).getAll().get(position).getPhotoPath();
InputStream is = context.getAssets().open(name);
Bitmap bmp = BitmapFactory.decodeStream(is);
is.close();
iv.setImageBitmap(bmp);
} catch (IOException e) {
e.printStackTrace();
}
return mv;
}
@Override
public void destroyItem(View view, int position, Object object) {
View mv = mListViews.get(position);
ImageView iv = (ImageView) mv.findViewById(R.id.imageView);
BitmapDrawable drawbale=(BitmapDrawable) iv.getDrawable();
drawbale.getBitmap().recycle();
}
上面是代碼 ,滑動多了會出現![圖片說明](http://img.ask.csdn.net/upload/201501/05/1420422751_173680.png)
BitmapFactory.Options opts=new BitmapFactory.Options();
//設置圖片的寬和高都為原先圖片的一半(壓縮)
opts.inSampleSize=2;
mBitmap=BitmapFactory.decodeFile(圖片地址, opts);