添加绘制到CirclePageIndicator

添加绘制到CirclePageIndicator

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

问题描述

如何添加,而不是将彩色图像圈pageindicator。我试图添加iconpage指标,但对点击的方法是行不通的,但我可以添加图片..在circlepageIndicator的onclick方法是工作,但如何添加可绘制,影像在CIRCLEPAGE指标。下面是我的code。

用于CirclePageIndicator

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

    最终浮动density1 = getResources()getDisplayMetrics()密度。
    indicator.setRadius(5 * density1);
    indicator.setPageColor(0xFF000000);
    indicator.setFillColor(0xFF888888);
  indicator.setStrokeColor(0x880000FF);
    indicator.setStrokeWidth(2 * density1);

    //我们设置这个的指标,而不是寻呼机
    indicator.setOnPageChangeListener(新ViewPager.OnPageChangeListener(){
        @覆盖
        公共无效onPageSelected(INT位置){
         // Toast.makeText(HomeSpizzaView.this,变更为网页+位置,Toast.LENGTH_SHORT).show();
        // pagerMenu.setCurrentItem(位置,假);
        }
        @覆盖
        公共无效onPageScrolled(INT位置,浮positionOffset,诠释positionOffsetPixels){
        }
        @覆盖
        公共无效onPageScrollStateChanged(INT状态){
        }
    });

    indicator.setOnClickListener(新OnClickListener(){
        @覆盖
        公共无效的onClick(视图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.thisgetCurrentItem+ nextItem,Toast.LENGTH_SHORT).show();
        }
    });
 

用于IconPageIndicator

  mIndicator =(IconPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);
    mIndicator.setLongClickable(真正的);

    //我们设置这个的指标,而不是寻呼机
    mIndicator.setOnPageChangeListener(新ViewPager.OnPageChangeListener(){
        @覆盖
        公共无效onPageSelected(INT位置){
            Toast.makeText(HomeSpizzaView.this,变更为网页+位置,Toast.LENGTH_SHORT).show();
            mPager.setCurrentItem(位置,假);
        }
        @覆盖
        公共无效onPageScrolled(INT位置,浮positionOffset,诠释positionOffsetPixels){
        }
        @覆盖
        公共无效onPageScrollStateChanged(INT状态){
        }
    });


    mIndicator.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图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.thisgetCurrentItem+ nextItem,Toast.LENGTH_SHORT).show();

        }

    });
 

解决方案

您在使用 CirclePageIndicator 对象来定制页指标。你可以设置图片或自定义颜色。你也可以使用XML定制这些指标,你可以找到例如,从给定的链接的Andr​​oid ViewPagerIndicator的GitHub的。如果你想使用的图标或图像,那么你可以使用下面的类 SampleIconsDefault.java 。从给定的样本

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.

USED CirclePageIndicator

       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();
        }
    });

USED IconPageIndicator

      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();

        }

    });
解决方案

You an use CirclePageIndicator object to customize page-indicator. you can set image or customize color.you can also customize these indicators using XML and you can find example from given link Android-ViewPagerIndicator's GitHub.If you want to use icon or image then you can use following class SampleIconsDefault.java. from given sample

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

08-04 01:02