首页 > 其他 > 详细

动态viewpager加载图片

时间:2015-08-14 15:42:05      阅读:241      评论:0      收藏:0      [点我收藏+]

传入网络图片地址就行了

public class MyPagerAdapter extends PagerAdapter {

    private List<String> viewlist;
    private Context mContext;

    public MyPagerAdapter(List<String> viewlist, Context mContext) {
        this.viewlist = viewlist;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return viewlist.size();
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        // TODO Auto-generated method stub
        return arg0 == arg1;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        // TODO Auto-generated method stub

        View imagelayout = LayoutInflater.from(mContext).inflate(
                R.layout.view1, null);
        ImageView imageview = (ImageView) imagelayout
                .findViewById(R.id.imageloaderimageview);

        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.ic_launcher)
                .showImageOnFail(R.drawable.icon15_03_middle)
                .showImageForEmptyUri(R.drawable.icon15_03_middle)
                .cacheInMemory(true).cacheOnDisc(true)
                .bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoader.getInstance().displayImage(viewlist.get(position),
                imageview, options);
           ((ViewPager) container).addView(imagelayout, 0);
        return imagelayout;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        // TODO Auto-generated method stub
          ((ViewPager) container).removeView((View) object);
    }

}

版权声明:本文为博主原创文章,未经博主允许不得转载。

动态viewpager加载图片

原文:http://blog.csdn.net/a4384142/article/details/47661897

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!