美文网首页
Android之父_viewPager无限轮播

Android之父_viewPager无限轮播

作者: _帅的掉渣 | 来源:发表于2017-10-26 10:02 被阅读0次
    //适配器监听小圆点
     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<ImageView>();
            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);
    
            }
    
    
    //添加选择器样式
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="oval"
        >
        <solid android:color="#0ff"/>
        <size android:width="15dp" android:height="15dp"/>
        <stroke android:color="#0ff" android:width="1dp"/>
    
    </shape>
    
    

    相关文章

      网友评论

          本文标题:Android之父_viewPager无限轮播

          本文链接:https://www.haomeiwen.com/subject/kcphpxtx.html