A powerful, customizable and extensible ViewPager indicator framework. As the best alternative of ViewPagerIndicator, TabLayout and PagerSlidingTabStrip.
Flutter_ConstraintLayout Another very good open source project of mine.
I have developed the world's fastest general purpose sorting algorithm, which is on average 3 times faster than Quicksort and up to 20 times faster, ChenSort
Simple steps, you can integrate MagicIndicator:
- checkout out MagicIndicator, which contains source code and demo
- import module magicindicator and add dependency:
implementation project(':magicindicator')or
repositories{... maven{url "https://jitpack.io" } } dependencies{... implementation 'com.github.hackware1993:MagicIndicator:1.6.0'// for support lib implementation 'com.github.hackware1993:MagicIndicator:1.7.0'// for androidx }- add MagicIndicator to your layout xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context="net.lucode.hackware.magicindicatordemo.MainActivity"> <net.lucode.hackware.magicindicator.MagicIndicator android:id="@+id/magic_indicator"android:layout_width="match_parent"android:layout_height="40dp" /> <android.support.v4.view.ViewPager android:id="@+id/view_pager"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1" /> </LinearLayout>- find MagicIndicator through code, initialize it:
MagicIndicatormagicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator); CommonNavigatorcommonNavigator = newCommonNavigator(this); commonNavigator.setAdapter(newCommonNavigatorAdapter(){@OverridepublicintgetCount(){returnmTitleDataList == null ? 0 : mTitleDataList.size()} @OverridepublicIPagerTitleViewgetTitleView(Contextcontext, finalintindex){ColorTransitionPagerTitleViewcolorTransitionPagerTitleView = newColorTransitionPagerTitleView(context); colorTransitionPagerTitleView.setNormalColor(Color.GRAY); colorTransitionPagerTitleView.setSelectedColor(Color.BLACK); colorTransitionPagerTitleView.setText(mTitleDataList.get(index)); colorTransitionPagerTitleView.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewview){mViewPager.setCurrentItem(index)} }); returncolorTransitionPagerTitleView} @OverridepublicIPagerIndicatorgetIndicator(Contextcontext){LinePagerIndicatorindicator = newLinePagerIndicator(context); indicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT); returnindicator} }); magicIndicator.setNavigator(commonNavigator);- work with ViewPager:
ViewPagerHelper.bind(magicIndicator, mViewPager);or
work with Fragment Container(switch Fragment by hide()、show()):
mFramentContainerHelper = newFragmentContainerHelper(magicIndicator); // ...mFragmentContainerHelper.handlePageSelected(pageIndex); // invoke when switch FragmentMagicIndicator can be easily extended:
- implement IPagerTitleView to customize tab:
publicclassMyPagerTitleViewextendsViewimplementsIPagerTitleView{publicMyPagerTitleView(Contextcontext){super(context)} @OverridepublicvoidonLeave(intindex, inttotalCount, floatleavePercent, booleanleftToRight){} @OverridepublicvoidonEnter(intindex, inttotalCount, floatenterPercent, booleanleftToRight){} @OverridepublicvoidonSelected(intindex, inttotalCount){} @OverridepublicvoidonDeselected(intindex, inttotalCount){} }- implement IPagerIndicator to customize indicator:
publicclassMyPagerIndicatorextendsViewimplementsIPagerIndicator{publicMyPagerIndicator(Contextcontext){super(context)} @OverridepublicvoidonPageSelected(intposition){} @OverridepublicvoidonPageScrolled(intposition, floatpositionOffset, intpositionOffsetPixels){} @OverridepublicvoidonPageScrollStateChanged(intstate){} @OverridepublicvoidonPositionDataProvide(List<PositionData> dataList){} }- use CommonPagerTitleView to load custom layout xml.
Now, enjoy yourself!
See extensions in app/src/main/java/net/lucode/hackware/magicindicatordemo/ext,more extensions adding...
An intermittent perfectionist.
Visit My Blog for more articles about MagicIndicator.
订阅我的微信公众号以及时获取 MagicIndicator 的最新动态。后续也会分享一些高质量的、独特的、有思想的 Flutter 和 Android 技术文章。
MIT License Copyright (c) 2016 hackware1993 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Have seen here, give a star?(都看到这儿了,何不给个...,哎,别走啊,star还没...)


