轮播图

- 编辑:小昭 -

轮播图

主方法
ArrayList<View> list=new ArrayList<>();
LayoutInflater li = getLayoutInflater();
        list.add(li.inflate(R.layout.lb1,null,false));
        list.add(li.inflate(R.layout.lb2,null,false));
        list.add(li.inflate(R.layout.lb3,null,false));
        vpadapter vv = new vpadapter(list);
        vpp.setAdapter(vv);
 
 
适配器
public class vpadapter extends PagerAdapter {
    private ArrayList<View> list;
 
    public vpadapter(ArrayList<View> list) {
        this.list = list;
    }
 
    @Override
    public int getCount() {
        return list.size();
    }
 
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }
 
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(list.get(position));
        return list.get(position);
    }
 
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
       container.removeView(list.get(position));
    }
}


用框架去实现

关联包
compile 'com.recker.flybanner:flybanner:1.3'

flybanner

fly.setImagesUrl(viewpager_url);

你会喜欢下面的文章? You'll like the following article.