将drawable添加到CirclePageIndicator [英] Adding drawable to CirclePageIndicator

查看:25
本文介绍了将drawable添加到CirclePageIndicator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将图像添加到圆形页面指示符而不是添加颜色.. 我尝试添加图标页面指示符,但点击方法不起作用,但我可以添加图像..在 circlepageIndicator 中,onclick 方法有效,但如何将可绘制的图像添加到 CIRCLEPAGE INDICATOR.以下是我的代码.

How to add image to circle pageindicator instead of adding color.. I have tried to add iconpage indicator but on click method is not working but i can add Image.. In circlepageIndicator onclick method is working but HOW TO ADD DRAWABLE, IMAGE TO CIRCLEPAGE INDICATOR. BELOW IS MY CODE.

使用圆形页面指示符

       indicator  = (CirclePageIndicator)findViewById(R.id.indicatorMenu);
    indicator.setViewPager(pagerMenu);

    final float density1 = getResources().getDisplayMetrics().density;
    indicator.setRadius(5 * density1);
    indicator.setPageColor(0xFF000000);
    indicator.setFillColor(0xFF888888);
  indicator.setStrokeColor(0x880000FF);
    indicator.setStrokeWidth(2 * density1);

    //We set this on the indicator, NOT the pager
    indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {             
        @Override
        public void onPageSelected(int position) {
         //   Toast.makeText(HomeSpizzaView.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
        //  pagerMenu.setCurrentItem(position, false);            
        }
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
        @Override
        public void onPageScrollStateChanged(int state) {               
        }
    });

    indicator.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            int currentItem = pagerMenu.getCurrentItem();
               int totalItems = pagerMenu.getAdapter().getCount();
               int nextItem = (currentItem + 1) % totalItems;
               pagerMenu.setCurrentItem(nextItem);
         Log.i("kkkkk", "getCurrentItem"+  nextItem);
         Toast.makeText(HomeSpizzaView.this, "getCurrentItem"+  nextItem, Toast.LENGTH_SHORT).show();
        }
    });

使用的图标页面指示器

      mIndicator  = (IconPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
    mIndicator.setLongClickable(true);

    //We set this on the indicator, NOT the pager
    mIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {             
        @Override
        public void onPageSelected(int position) {
            Toast.makeText(HomeSpizzaView.this, "Changed to page " + position, Toast.LENGTH_SHORT).show();
            mPager.setCurrentItem(position, false);    
        }
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
        @Override
        public void onPageScrollStateChanged(int state) {               
        }
    });


    mIndicator.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View v) {
            int currentItem = pagerMenu.getCurrentItem();
               int totalItems = pagerMenu.getAdapter().getCount();
               int nextItem = (currentItem + 1) % totalItems;
               pagerMenu.setCurrentItem(nextItem);
         Log.i("mmmmmmmmmmmm", "getCurrentItem"+  nextItem);
         Toast.makeText(HomeSpizzaView.this, "getCurrentItem"+  nextItem, Toast.LENGTH_SHORT).show();

        }

    });

推荐答案

我遇到了同样的问题,唯一的解决方案是创建自己的库来解决这个问题.

I had the same problem and the only solution was to create my own library to do that.

https://github.com/augustopicciani/DrawablePageIndicator

这篇关于将drawable添加到CirclePageIndicator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆