码迷,mamicode.com
首页 > 其他好文 > 详细

动态viewpager加载图片

时间:2015-08-14 15:45:21      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:viewpager   动态图片   

传入网络图片地址就行了

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加载图片

标签:viewpager   动态图片   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!