Android之父_viewPager无限轮播

//适配器监听小圆点
 vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            }
            @Override
            public void onPageSelected(int position) {
                int index = position % list_doc.size();
                for (int i = 0; i < list_doc.size(); i++) {
                    list_doc.get(i).setBackgroundResource(R.drawable.doc_uncheck);
                }
                list_doc.get(index).setBackgroundResource(R.drawable.doc_check);
            }
            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void lunbo(int index) {
        vp.setCurrentItem(index);
    }

//动态添加小圆点
//初始化小圆点
    public void initDoc() {
        list_doc = new ArrayList();
        if (shouye_vp != null && shouye_vp.getStories().size() > 0) {
            for (int i = 0; i < shouye_vp.getStories().size(); i++) {
                ImageView iv = new ImageView(context);
                params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                params.rightMargin = 10;
                iv.setLayoutParams(params);
                if (i == 0) {
                    iv.setBackgroundResource(R.drawable.doc_check);
                } else {
                    iv.setBackgroundResource(R.drawable.doc_uncheck);
                }
                view.showDoc(iv);
                list_doc.add(iv);
            }
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    index++;
                    view.lunbo(index);
                    handler.postDelayed(this, 3000);
                }
            }, 3000);
            view.listener(list_doc);

        }

//添加选择器样式

    
    
    



你可能感兴趣的:(Android之父_viewPager无限轮播)