Android Implement a page counter like the one on the home screen

后端 未结 1 1256
悲&欢浪女
悲&欢浪女 2021-01-01 05:13

Does anyone know of an example of how to do the page/view counter (little dots) like the one on home screen?

Like this example:

1条回答
  •  遥遥无期
    2021-01-01 05:44

    PagerTitleStrip is what you use with ViewPager to indicate what page you're on. It's something you add to your XML.

    Layout XML:

    
    
    
    
        
    
    
    
    

    And in your PagerAdapter:

    @Override
        public CharSequence getPageTitle (int position) {
            return "Your static title";
        }
    

    However, PagerTitleStrip isn't very customizable, but ViewPagerIndicator is very customizable and includes the dotted indicator that you're looking for. You'll need to theme it to recreate the picture in your OP.

    Circle indicator with ViewPagerIndicator:

    
    
    
    
    
    
    

    Then in your code:

    CirclePageIndicator mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
            mIndicator.setViewPager(mPager);
    

    ViewPagerExtensions is another open source library that offers custom views for ViewPager you might be interested in.

    0 讨论(0)
提交回复
热议问题