摘要:第四种ImageGallery效果如图: 测试关键代码: public class ImageGalleryActivity extends BaseActivity{private Gallery gallery;private DisplayImageOptions options;public void onCreate(Bundle savedInstanc
第四种ImageGallery效果如图:
![](https://i-blog.csdnimg.cn/blog_migrate/34edb5df77801e36332742cfd87da3d3.png)
测试关键代码:
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);
}
@Override
protected 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();
}
@Override
public int getCount()
{
return images.length;
}
@Override
public Object getItem(int position)
{
return position;
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public 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;
}
}
}
实例中通过imageLoader成员负责图片操作!初始化如下:
protected ImageLoader imageLoader = ImageLoader.getInstance();
protected ImageLoader imageLoader = ImageLoader.getInstance();
此处主要是围绕UniversalImageLoader使用的介绍