轮播图永远滚动不完

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/xiyangyang8110/article/details/52821607
 @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }
package com.jiawabang.ui.adapter;

import android.app.Activity;
import android.graphics.Bitmap;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jiawabang.Model.ArticleModel;
import com.jiawabang.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

import java.util.List;

/**
 * Created by jiawayun on 2016/9/8.
 */
public class ViewPagerHomeFragmentAdapter extends PagerAdapter {
    private List<ArticleModel.ArticleDataModel> mHomeBannerEntities;
    private Activity mActivity;
    private LayoutInflater mLayoutInflater;
    private DisplayImageOptions mOptions;

    public ViewPagerHomeFragmentAdapter(List<ArticleModel.ArticleDataModel> mHomeBannerEntities, Activity mActivity) {
        this.mHomeBannerEntities = mHomeBannerEntities;
        this.mActivity = mActivity;
        this.mLayoutInflater = mActivity.getLayoutInflater();
        mOptions = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.product_loading)
                .showImageOnFail(R.drawable.product_loading)
                .showImageOnLoading(R.drawable.product_loading)
                .resetViewBeforeLoading(true)
                .cacheOnDisk(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .considerExifParams(false)
                .displayer(new FadeInBitmapDisplayer(300))
                .build();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView mImageView = (ImageView) mLayoutInflater.inflate(R.layout.item_viewpager_homefragment, container, false);
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View mView) {
//                Intent mIntent=new Intent(mActivity, LunbotuActivity.class);
//                Context.startActivity(mIntent);

            }
        });
        container.addView(mImageView);
//         Log.e("108", "run:---------> "+ mHomeBannerEntities.get(position % mHomeBannerEntities.size()).picurl);
        //500轮播完了会报错,ArithmeticException算数异常,分母是0,可改为无穷大
        ImageLoader.getInstance().displayImage("http://dev.jiawabang.com/cofco-fileserver/"+mHomeBannerEntities.get(position % mHomeBannerEntities.size()).picurl, mImageView, mOptions);

        return mImageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}
展开阅读全文

没有更多推荐了,返回首页