本文主要是介绍android平台UniversalImageLoader(异步加载大量图片,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
摘要:第四种ImageGallery效果如图: 测试关键代码: public class ImageGalleryActivity extends BaseActivity{private Gallery gallery;private DisplayImageOptions options;public void onCreate(Bundle savedInstanc
public class ImageGalleryActivity extends BaseActivity
{private Gallery gallery;private DisplayImageOptions options;public void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.ac_image_gallery);Bundle bundle = getIntent().getExtras();String[] imageUrls = bundle.getStringArray(Extra.IMAGES);int galleryPosition = bundle.getInt(Extra.IMAGE_POSITION, 0);options = new DisplayImageOptions.Builder().showImageForEmptyUri(R.drawable.image_for_empty_url).showStubImage(R.drawable.stub_image).cacheInMemory().cacheOnDisc().build();gallery = (Gallery) findViewById(R.id.gallery);gallery.setAdapter(new ImagePagerAdapter(imageUrls));gallery.setSelection(galleryPosition);}@Overrideprotected void onStop(){imageLoader.stop();super.onStop();}private class ImagePagerAdapter extends BaseAdapter{private String[] images;private LayoutInflater inflater;ImagePagerAdapter(String[] images){this.images = images;inflater = getLayoutInflater();}@Overridepublic int getCount(){return images.length;}@Overridepublic Object getItem(int position){return position;}@Overridepublic long getItemId(int position){return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent){ImageView imageView = (ImageView) convertView;if (imageView == null){imageView = (ImageView) inflater.inflate(R.layout.item_gallery_image, parent, false);}imageLoader.displayImage(images[position], imageView, options);return imageView;}}
}
protected ImageLoader imageLoader = ImageLoader.getInstance();
此处主要是围绕UniversalImageLoader使用的介绍
这篇关于android平台UniversalImageLoader(异步加载大量图片的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!