Android MagicIndicator 指示器 导航

Android MagicIndicator 指示器 导航,第1张

概述由于一直使用的FlycoTabLayout很久没有维护了,所以毅然决然找一个新的框架.https://github.com/hackware1993/MagicIndicator首先把六个自定义的列出来CommonPagerIndicator/***通用的indicator,支持外面设置Drawable*Createdbyhackwareon2016/11/14.*/publi

由于一直使用的FlycoTabLayout 很久没有维护了,所以毅然决然找一个新的框架.

https://github.com/hackware1993/MagicIndicator

首先把六个自定义的列出来

CommonPagerIndicator
/** * 通用的indicator,支持外面设置Drawable * Created by Hackware on 2016/11/14. */public class CommonPagerIndicator extends VIEw implements IPagerIndicator {    public static final int MODE_MATCH_EDGE = 0;   // drawable宽度 == Title宽度 - 2 * mXOffset    public static final int MODE_WRAP_CONTENT = 1;    // drawable宽度 == Title内容宽度 - 2 * mXOffset    public static final int MODE_EXACTLY = 2;    private int mMode;  // 默认为MODE_MATCH_EDGE模式    private Drawable mIndicatorDrawable;    // 控制动画    private Interpolator mStartInterpolator = new linearInterpolator();    private Interpolator mEndInterpolator = new linearInterpolator();    private float mDrawableHeight;    private float mDrawableWIDth;    private float mYOffset;    private float mXOffset;    private List<positionData> mpositionDataList;    private Rect mDrawableRect = new Rect();    public CommonPagerIndicator(Context context) {        super(context);    }    @OverrIDe    public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {        if (mIndicatorDrawable == null) {            return;        }        if (mpositionDataList == null || mpositionDataList.isEmpty()) {            return;        }        // 计算锚点位置        positionData current = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position);        positionData next = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position + 1);        float leftX;        float nextleftX;        float rightX;        float nextRightX;        if (mMode == MODE_MATCH_EDGE) {            leftX = current.mleft + mXOffset;            nextleftX = next.mleft + mXOffset;            rightX = current.mRight - mXOffset;            nextRightX = next.mRight - mXOffset;            mDrawableRect.top = (int) mYOffset;            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        } else if (mMode == MODE_WRAP_CONTENT) {            leftX = current.mContentleft + mXOffset;            nextleftX = next.mContentleft + mXOffset;            rightX = current.mContentRight - mXOffset;            nextRightX = next.mContentRight - mXOffset;            mDrawableRect.top = (int) (current.mContenttop - mYOffset);            mDrawableRect.bottom = (int) (current.mContentBottom + mYOffset);        } else {    // MODE_EXACTLY            leftX = current.mleft + (current.wIDth() - mDrawableWIDth) / 2;            nextleftX = next.mleft + (next.wIDth() - mDrawableWIDth) / 2;            rightX = current.mleft + (current.wIDth() + mDrawableWIDth) / 2;            nextRightX = next.mleft + (next.wIDth() + mDrawableWIDth) / 2;            mDrawableRect.top = (int) (getHeight() - mDrawableHeight - mYOffset);            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        }        mDrawableRect.left = (int) (leftX + (nextleftX - leftX) * mStartInterpolator.getInterpolation(positionOffset));        mDrawableRect.right = (int) (rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset));        mIndicatorDrawable.setBounds(mDrawableRect);        invalIDate();    }    @OverrIDe    public voID onPageSelected(int position) {    }    @OverrIDe    public voID onPageScrollStateChanged(int state) {    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        if (mIndicatorDrawable != null) {            mIndicatorDrawable.draw(canvas);        }    }    @OverrIDe    public voID onpositionDataProvIDe(List<positionData> dataList) {        mpositionDataList = dataList;    }    public Drawable getIndicatorDrawable() {        return mIndicatorDrawable;    }    public voID setIndicatorDrawable(Drawable indicatorDrawable) {        mIndicatorDrawable = indicatorDrawable;    }    public Interpolator getStartInterpolator() {        return mStartInterpolator;    }    public voID setStartInterpolator(Interpolator startInterpolator) {        mStartInterpolator = startInterpolator;    }    public Interpolator getEndInterpolator() {        return mEndInterpolator;    }    public voID setEndInterpolator(Interpolator endInterpolator) {        mEndInterpolator = endInterpolator;    }    public int getMode() {        return mMode;    }    public voID setMode(int mode) {        if (mode == MODE_EXACTLY || mode == MODE_MATCH_EDGE || mode == MODE_WRAP_CONTENT) {            mMode = mode;        } else {            throw new IllegalArgumentException("mode " + mode + " not supported.");        }    }    public float getDrawableHeight() {        return mDrawableHeight;    }    public voID setDrawableHeight(float drawableHeight) {        mDrawableHeight = drawableHeight;    }    public float getDrawableWIDth() {        return mDrawableWIDth;    }    public voID setDrawableWIDth(float drawableWIDth) {        mDrawableWIDth = drawableWIDth;    }    public float getYOffset() {        return mYOffset;    }    public voID setYOffset(float yOffset) {        mYOffset = yOffset;    }    public float getXOffset() {        return mXOffset;    }    public voID setXOffset(float xOffset) {        mXOffset = xOffset;    }}

DotPagerIndicator
/** * 非手指跟随的小圆点指示器 * Created by Hackware on 2016/7/13. */public class DotPagerIndicator extends VIEw implements IPagerIndicator {    private List<positionData> mDataList;    private float mRadius;    private float mYOffset;    private int mDotcolor;    private float mCircleCenterX;    private Paint mPaint = new Paint(Paint.ANTI_AliAS_FLAG);    public DotPagerIndicator(Context context) {        super(context);        mRadius = UIUtil.dip2px(context, 3);        mYOffset = UIUtil.dip2px(context, 3);        mDotcolor = color.WHITE;    }    @OverrIDe    public voID onPageSelected(int position) {        if (mDataList == null || mDataList.isEmpty()) {            return;        }        positionData data = mDataList.get(position);        mCircleCenterX = data.mleft + data.wIDth() / 2;        invalIDate();    }    @OverrIDe    public voID onpositionDataProvIDe(List<positionData> dataList) {        mDataList = dataList;    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        super.onDraw(canvas);        mPaint.setcolor(mDotcolor);        canvas.drawCircle(mCircleCenterX, getHeight() - mYOffset - mRadius, mRadius, mPaint);    }    @OverrIDe    public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {    }    @OverrIDe    public voID onPageScrollStateChanged(int state) {    }    public float geTradius() {        return mRadius;    }    public voID seTradius(float radius) {        mRadius = radius;        invalIDate();    }    public float getYOffset() {        return mYOffset;    }    public voID setYOffset(float yOffset) {        mYOffset = yOffset;        invalIDate();    }    public int getDotcolor() {        return mDotcolor;    }    public voID setDotcolor(int dotcolor) {        mDotcolor = dotcolor;        invalIDate();    }}

DummyCircleNavigator
/** * 通用的indicator,支持外面设置Drawable * Created by Hackware on 2016/11/14. */public class CommonPagerIndicator extends VIEw implements IPagerIndicator {    public static final int MODE_MATCH_EDGE = 0;   // drawable宽度 == Title宽度 - 2 * mXOffset    public static final int MODE_WRAP_CONTENT = 1;    // drawable宽度 == Title内容宽度 - 2 * mXOffset    public static final int MODE_EXACTLY = 2;    // 默认为MODE_MATCH_EDGE模式    private int mMode;    private Drawable mIndicatorDrawable;    // 控制动画    private Interpolator mStartInterpolator = new linearInterpolator();    private Interpolator mEndInterpolator = new linearInterpolator();    private float mDrawableHeight;    private float mDrawableWIDth;    private float mYOffset;    private float mXOffset;    private List<positionData> mpositionDataList;    private Rect mDrawableRect = new Rect();    public CommonPagerIndicator(Context context) {        super(context);    }    @OverrIDe    public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {        if (mIndicatorDrawable == null) {            return;        }        if (mpositionDataList == null || mpositionDataList.isEmpty()) {            return;        }        // 计算锚点位置        positionData current = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position);        positionData next = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position + 1);        float leftX;        float nextleftX;        float rightX;        float nextRightX;        if (mMode == MODE_MATCH_EDGE) {            leftX = current.mleft + mXOffset;            nextleftX = next.mleft + mXOffset;            rightX = current.mRight - mXOffset;            nextRightX = next.mRight - mXOffset;            mDrawableRect.top = (int) mYOffset;            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        } else if (mMode == MODE_WRAP_CONTENT) {            leftX = current.mContentleft + mXOffset;            nextleftX = next.mContentleft + mXOffset;            rightX = current.mContentRight - mXOffset;            nextRightX = next.mContentRight - mXOffset;            mDrawableRect.top = (int) (current.mContenttop - mYOffset);            mDrawableRect.bottom = (int) (current.mContentBottom + mYOffset);        } else {    // MODE_EXACTLY            leftX = current.mleft + (current.wIDth() - mDrawableWIDth) / 2;            nextleftX = next.mleft + (next.wIDth() - mDrawableWIDth) / 2;            rightX = current.mleft + (current.wIDth() + mDrawableWIDth) / 2;            nextRightX = next.mleft + (next.wIDth() + mDrawableWIDth) / 2;            mDrawableRect.top = (int) (getHeight() - mDrawableHeight - mYOffset);            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        }        mDrawableRect.left = (int) (leftX + (nextleftX - leftX) * mStartInterpolator.getInterpolation(positionOffset));        mDrawableRect.right = (int) (rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset));        mIndicatorDrawable.setBounds(mDrawableRect);        invalIDate();    }    @OverrIDe    public voID onPageSelected(int position) {    }    @OverrIDe    public voID onPageScrollStateChanged(int state) {    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        if (mIndicatorDrawable != null) {            mIndicatorDrawable.draw(canvas);        }    }    @OverrIDe    public voID onpositionDataProvIDe(List<positionData> dataList) {        mpositionDataList = dataList;    }    public Drawable getIndicatorDrawable() {        return mIndicatorDrawable;    }    public voID setIndicatorDrawable(Drawable indicatorDrawable) {        mIndicatorDrawable = indicatorDrawable;    }    public Interpolator getStartInterpolator() {        return mStartInterpolator;    }    public voID setStartInterpolator(Interpolator startInterpolator) {        mStartInterpolator = startInterpolator;    }    public Interpolator getEndInterpolator() {        return mEndInterpolator;    }    public voID setEndInterpolator(Interpolator endInterpolator) {        mEndInterpolator = endInterpolator;    }    public int getMode() {        return mMode;    }    public voID setMode(int mode) {        if (mode == MODE_EXACTLY || mode == MODE_MATCH_EDGE || mode == MODE_WRAP_CONTENT) {            mMode = mode;        } else {            throw new IllegalArgumentException("mode " + mode + " not supported.");        }    }    public float getDrawableHeight() {        return mDrawableHeight;    }    public voID setDrawableHeight(float drawableHeight) {        mDrawableHeight = drawableHeight;    }    public float getDrawableWIDth() {        return mDrawableWIDth;    }    public voID setDrawableWIDth(float drawableWIDth) {        mDrawableWIDth = drawableWIDth;    }    public float getYOffset() {        return mYOffset;    }    public voID setYOffset(float yOffset) {        mYOffset = yOffset;    }    public float getXOffset() {        return mXOffset;    }    public voID setXOffset(float xOffset) {        mXOffset = xOffset;    }}

ScaleCircleNavigator
/** * 通用的indicator,支持外面设置Drawable * Created by Hackware on 2016/11/14. */public class CommonPagerIndicator extends VIEw implements IPagerIndicator {    public static final int MODE_MATCH_EDGE = 0;   // drawable宽度 == Title宽度 - 2 * mXOffset    public static final int MODE_WRAP_CONTENT = 1;    // drawable宽度 == Title内容宽度 - 2 * mXOffset    public static final int MODE_EXACTLY = 2;    // 默认为MODE_MATCH_EDGE模式    private int mMode;    private Drawable mIndicatorDrawable;    // 控制动画    private Interpolator mStartInterpolator = new linearInterpolator();    private Interpolator mEndInterpolator = new linearInterpolator();    private float mDrawableHeight;    private float mDrawableWIDth;    private float mYOffset;    private float mXOffset;    private List<positionData> mpositionDataList;    private Rect mDrawableRect = new Rect();    public CommonPagerIndicator(Context context) {        super(context);    }    @OverrIDe    public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {        if (mIndicatorDrawable == null) {            return;        }        if (mpositionDataList == null || mpositionDataList.isEmpty()) {            return;        }        // 计算锚点位置        positionData current = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position);        positionData next = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position + 1);        float leftX;        float nextleftX;        float rightX;        float nextRightX;        if (mMode == MODE_MATCH_EDGE) {            leftX = current.mleft + mXOffset;            nextleftX = next.mleft + mXOffset;            rightX = current.mRight - mXOffset;            nextRightX = next.mRight - mXOffset;            mDrawableRect.top = (int) mYOffset;            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        } else if (mMode == MODE_WRAP_CONTENT) {            leftX = current.mContentleft + mXOffset;            nextleftX = next.mContentleft + mXOffset;            rightX = current.mContentRight - mXOffset;            nextRightX = next.mContentRight - mXOffset;            mDrawableRect.top = (int) (current.mContenttop - mYOffset);            mDrawableRect.bottom = (int) (current.mContentBottom + mYOffset);        } else {    // MODE_EXACTLY            leftX = current.mleft + (current.wIDth() - mDrawableWIDth) / 2;            nextleftX = next.mleft + (next.wIDth() - mDrawableWIDth) / 2;            rightX = current.mleft + (current.wIDth() + mDrawableWIDth) / 2;            nextRightX = next.mleft + (next.wIDth() + mDrawableWIDth) / 2;            mDrawableRect.top = (int) (getHeight() - mDrawableHeight - mYOffset);            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        }        mDrawableRect.left = (int) (leftX + (nextleftX - leftX) * mStartInterpolator.getInterpolation(positionOffset));        mDrawableRect.right = (int) (rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset));        mIndicatorDrawable.setBounds(mDrawableRect);        invalIDate();    }    @OverrIDe    public voID onPageSelected(int position) {    }    @OverrIDe    public voID onPageScrollStateChanged(int state) {    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        if (mIndicatorDrawable != null) {            mIndicatorDrawable.draw(canvas);        }    }    @OverrIDe    public voID onpositionDataProvIDe(List<positionData> dataList) {        mpositionDataList = dataList;    }    public Drawable getIndicatorDrawable() {        return mIndicatorDrawable;    }    public voID setIndicatorDrawable(Drawable indicatorDrawable) {        mIndicatorDrawable = indicatorDrawable;    }    public Interpolator getStartInterpolator() {        return mStartInterpolator;    }    public voID setStartInterpolator(Interpolator startInterpolator) {        mStartInterpolator = startInterpolator;    }    public Interpolator getEndInterpolator() {        return mEndInterpolator;    }    public voID setEndInterpolator(Interpolator endInterpolator) {        mEndInterpolator = endInterpolator;    }    public int getMode() {        return mMode;    }    public voID setMode(int mode) {        if (mode == MODE_EXACTLY || mode == MODE_MATCH_EDGE || mode == MODE_WRAP_CONTENT) {            mMode = mode;        } else {            throw new IllegalArgumentException("mode " + mode + " not supported.");        }    }    public float getDrawableHeight() {        return mDrawableHeight;    }    public voID setDrawableHeight(float drawableHeight) {        mDrawableHeight = drawableHeight;    }    public float getDrawableWIDth() {        return mDrawableWIDth;    }    public voID setDrawableWIDth(float drawableWIDth) {        mDrawableWIDth = drawableWIDth;    }    public float getYOffset() {        return mYOffset;    }    public voID setYOffset(float yOffset) {        mYOffset = yOffset;    }    public float getXOffset() {        return mXOffset;    }    public voID setXOffset(float xOffset) {        mXOffset = xOffset;    }}

colorFlipPagerTitleVIEw
public class colorFlipPagerTitleVIEw extends SimplePagerTitleVIEw {    private float mChangePercent = 0.5f;    public colorFlipPagerTitleVIEw(Context context) {        super(context);    }    @OverrIDe    public voID onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {        if (leavePercent >= mChangePercent) {            setTextcolor(mnormalcolor);        } else {            setTextcolor(mSelectedcolor);        }    }    @OverrIDe    public voID onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {        if (enterPercent >= mChangePercent) {            setTextcolor(mSelectedcolor);        } else {            setTextcolor(mnormalcolor);        }    }    @OverrIDe    public voID onSelected(int index, int totalCount) {    }    @OverrIDe    public voID ondeselected(int index, int totalCount) {    }    public float getChangePercent() {        return mChangePercent;    }    public voID setChangePercent(float changePercent) {        mChangePercent = changePercent;    }}

ScaleTransitionPagerTitleVIEw
/** * 通用的indicator,支持外面设置Drawable * Created by Hackware on 2016/11/14. */public class CommonPagerIndicator extends VIEw implements IPagerIndicator {    public static final int MODE_MATCH_EDGE = 0;   // drawable宽度 == Title宽度 - 2 * mXOffset    public static final int MODE_WRAP_CONTENT = 1;    // drawable宽度 == Title内容宽度 - 2 * mXOffset    public static final int MODE_EXACTLY = 2;    // 默认为MODE_MATCH_EDGE模式    private int mMode;    private Drawable mIndicatorDrawable;    // 控制动画    private Interpolator mStartInterpolator = new linearInterpolator();    private Interpolator mEndInterpolator = new linearInterpolator();    private float mDrawableHeight;    private float mDrawableWIDth;    private float mYOffset;    private float mXOffset;    private List<positionData> mpositionDataList;    private Rect mDrawableRect = new Rect();    public CommonPagerIndicator(Context context) {        super(context);    }    @OverrIDe    public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {        if (mIndicatorDrawable == null) {            return;        }        if (mpositionDataList == null || mpositionDataList.isEmpty()) {            return;        }        // 计算锚点位置        positionData current = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position);        positionData next = FragmentContainerHelper.getImitativepositionData(mpositionDataList, position + 1);        float leftX;        float nextleftX;        float rightX;        float nextRightX;        if (mMode == MODE_MATCH_EDGE) {            leftX = current.mleft + mXOffset;            nextleftX = next.mleft + mXOffset;            rightX = current.mRight - mXOffset;            nextRightX = next.mRight - mXOffset;            mDrawableRect.top = (int) mYOffset;            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        } else if (mMode == MODE_WRAP_CONTENT) {            leftX = current.mContentleft + mXOffset;            nextleftX = next.mContentleft + mXOffset;            rightX = current.mContentRight - mXOffset;            nextRightX = next.mContentRight - mXOffset;            mDrawableRect.top = (int) (current.mContenttop - mYOffset);            mDrawableRect.bottom = (int) (current.mContentBottom + mYOffset);        } else {    // MODE_EXACTLY            leftX = current.mleft + (current.wIDth() - mDrawableWIDth) / 2;            nextleftX = next.mleft + (next.wIDth() - mDrawableWIDth) / 2;            rightX = current.mleft + (current.wIDth() + mDrawableWIDth) / 2;            nextRightX = next.mleft + (next.wIDth() + mDrawableWIDth) / 2;            mDrawableRect.top = (int) (getHeight() - mDrawableHeight - mYOffset);            mDrawableRect.bottom = (int) (getHeight() - mYOffset);        }        mDrawableRect.left = (int) (leftX + (nextleftX - leftX) * mStartInterpolator.getInterpolation(positionOffset));        mDrawableRect.right = (int) (rightX + (nextRightX - rightX) * mEndInterpolator.getInterpolation(positionOffset));        mIndicatorDrawable.setBounds(mDrawableRect);        invalIDate();    }    @OverrIDe    public voID onPageSelected(int position) {    }    @OverrIDe    public voID onPageScrollStateChanged(int state) {    }    @OverrIDe    protected voID onDraw(Canvas canvas) {        if (mIndicatorDrawable != null) {            mIndicatorDrawable.draw(canvas);        }    }    @OverrIDe    public voID onpositionDataProvIDe(List<positionData> dataList) {        mpositionDataList = dataList;    }    public Drawable getIndicatorDrawable() {        return mIndicatorDrawable;    }    public voID setIndicatorDrawable(Drawable indicatorDrawable) {        mIndicatorDrawable = indicatorDrawable;    }    public Interpolator getStartInterpolator() {        return mStartInterpolator;    }    public voID setStartInterpolator(Interpolator startInterpolator) {        mStartInterpolator = startInterpolator;    }    public Interpolator getEndInterpolator() {        return mEndInterpolator;    }    public voID setEndInterpolator(Interpolator endInterpolator) {        mEndInterpolator = endInterpolator;    }    public int getMode() {        return mMode;    }    public voID setMode(int mode) {        if (mode == MODE_EXACTLY || mode == MODE_MATCH_EDGE || mode == MODE_WRAP_CONTENT) {            mMode = mode;        } else {            throw new IllegalArgumentException("mode " + mode + " not supported.");        }    }    public float getDrawableHeight() {        return mDrawableHeight;    }    public voID setDrawableHeight(float drawableHeight) {        mDrawableHeight = drawableHeight;    }    public float getDrawableWIDth() {        return mDrawableWIDth;    }    public voID setDrawableWIDth(float drawableWIDth) {        mDrawableWIDth = drawableWIDth;    }    public float getYOffset() {        return mYOffset;    }    public voID setYOffset(float yOffset) {        mYOffset = yOffset;    }    public float getXOffset() {        return mXOffset;    }    public voID setXOffset(float xOffset) {        mXOffset = xOffset;    }}

把效果演示一下:

private static final String[] CHANNELS = new String[]{"CUPCAKE", "DONUT", "ECLAIR", "GINGERBREAD", "HONEYCOMB", "ICE_CREAM_SANDWICH", "JELLY_BEAN", "KITKAT", "LolliPOP"};    private List<String> mDataList = Arrays.asList(CHANNELS);    private VIEwPager mVIEwPager;    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentVIEw(R.layout.activity_main2);        BlankFragment b1 = new BlankFragment();        BlankFragment b2 = new BlankFragment();        BlankFragment b3 = new BlankFragment();        BlankFragment b4 = new BlankFragment();        BlankFragment b5 = new BlankFragment();        BlankFragment b6 = new BlankFragment();        BlankFragment b7 = new BlankFragment();        BlankFragment b8 = new BlankFragment();        BlankFragment b9 = new BlankFragment();        FmPagerAdapter fmPagerAdapter = new FmPagerAdapter(getSupportFragmentManager());        ArrayList<Fragment> fragmentList = new ArrayList<>();        fragmentList.add(b1);        fragmentList.add(b2);        fragmentList.add(b3);        fragmentList.add(b4);        fragmentList.add(b5);        fragmentList.add(b6);        fragmentList.add(b7);        fragmentList.add(b8);        fragmentList.add(b9);        fmPagerAdapter.setmFragments(fragmentList);        mVIEwPager = (VIEwPager) findVIEwByID(R.ID.vIEw_pager);        mVIEwPager.setAdapter(fmPagerAdapter);        initMagicIndicator1();        initMagicIndicator2();        initMagicIndicator3();        initMagicIndicator4();        initMagicIndicator5();        initMagicIndicator6();        initMagicIndicator7();        initMagicIndicator8();        initMagicIndicator9();    }    private voID initMagicIndicator1() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator1);        magicIndicator.setBackgroundcolor(color.parsecolor("#d43d3d"));        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setSkimOver(true);        int padding = UIUtil.getScreenWIDth(this) / 2;        commonNavigator.setRightpadding(padding);        commonNavigator.setleftpadding(padding);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                ClipPagerTitleVIEw clipPagerTitleVIEw = new ClipPagerTitleVIEw(context);                clipPagerTitleVIEw.setText(mDataList.get(index));                clipPagerTitleVIEw.setTextcolor(color.parsecolor("#f2c4c4"));                clipPagerTitleVIEw.setClipcolor(color.WHITE);                clipPagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return clipPagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                return null;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator2() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator2);        magicIndicator.setBackgroundcolor(color.parsecolor("#00c853"));        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setScrollPivotX(0.25f);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new SimplePagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#c8e6c9"));                simplePagerTitleVIEw.setSelectedcolor(color.WHITE);                simplePagerTitleVIEw.setTextSize(12);                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                linePagerIndicator indicator = new linePagerIndicator(context);                indicator.setMode(linePagerIndicator.MODE_EXACTLY);                indicator.setYOffset(UIUtil.dip2px(context, 3));                indicator.setcolors(color.parsecolor("#ffffff"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator3() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator3);        magicIndicator.setBackgroundcolor(color.BLACK);        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new colorTransitionPagerTitleVIEw(context);                simplePagerTitleVIEw.setnormalcolor(color.GRAY);                simplePagerTitleVIEw.setSelectedcolor(color.WHITE);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                linePagerIndicator linePagerIndicator = new linePagerIndicator(context);                linePagerIndicator.setMode(linePagerIndicator.MODE_WRAP_CONTENT);                linePagerIndicator.setcolors(color.WHITE);                return linePagerIndicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator4() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator4);        magicIndicator.setBackgroundcolor(color.parsecolor("#455a64"));        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new colorTransitionPagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#88ffffff"));                simplePagerTitleVIEw.setSelectedcolor(color.WHITE);                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                linePagerIndicator indicator = new linePagerIndicator(context);                indicator.setcolors(color.parsecolor("#40c4ff"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator5() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator5);        magicIndicator.setBackgroundcolor(color.WHITE);        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setScrollPivotX(0.8f);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new ScaleTransitionPagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setTextSize(18);                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#616161"));                simplePagerTitleVIEw.setSelectedcolor(color.parsecolor("#f57c00"));                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                linePagerIndicator indicator = new linePagerIndicator(context);                indicator.setStartInterpolator(new AccelerateInterpolator());                indicator.setEndInterpolator(new DecelerateInterpolator(1.6f));                indicator.setYOffset(UIUtil.dip2px(context, 39));                indicator.setlineHeight(UIUtil.dip2px(context, 1));                indicator.setcolors(color.parsecolor("#f57c00"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator6() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator6);        magicIndicator.setBackgroundcolor(color.WHITE);        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new ScaleTransitionPagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setTextSize(18);                simplePagerTitleVIEw.setnormalcolor(color.GRAY);                simplePagerTitleVIEw.setSelectedcolor(color.BLACK);                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                BezIErPagerIndicator indicator = new BezIErPagerIndicator(context);                indicator.setcolors(color.parsecolor("#ff4a42"), color.parsecolor("#fcde64"), color.parsecolor("#73e8f4"), color.parsecolor("#76b0ff"), color.parsecolor("#c683fe"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator7() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator7);        magicIndicator.setBackgroundcolor(color.parsecolor("#fafafa"));        CommonNavigator commonNavigator7 = new CommonNavigator(this);        commonNavigator7.setScrollPivotX(0.65f);        commonNavigator7.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new colorFlipPagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#9e9e9e"));                simplePagerTitleVIEw.setSelectedcolor(color.parsecolor("#00c853"));                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                linePagerIndicator indicator = new linePagerIndicator(context);                indicator.setMode(linePagerIndicator.MODE_EXACTLY);                indicator.setlineHeight(UIUtil.dip2px(context, 6));                indicator.setlinewidth(UIUtil.dip2px(context, 10));                indicator.setRoundRadius(UIUtil.dip2px(context, 3));                indicator.setStartInterpolator(new AccelerateInterpolator());                indicator.setEndInterpolator(new DecelerateInterpolator(2.0f));                indicator.setcolors(color.parsecolor("#00c853"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator7);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator8() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator8);        magicIndicator.setBackgroundcolor(color.WHITE);        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setScrollPivotX(0.35f);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new SimplePagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#333333"));                simplePagerTitleVIEw.setSelectedcolor(color.parsecolor("#e94220"));                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                WrapPagerIndicator indicator = new WrapPagerIndicator(context);                indicator.setFillcolor(color.parsecolor("#ebe4e3"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }    private voID initMagicIndicator9() {        MagicIndicator magicIndicator = (MagicIndicator) findVIEwByID(R.ID.magic_indicator9);        magicIndicator.setBackgroundcolor(color.WHITE);        CommonNavigator commonNavigator = new CommonNavigator(this);        commonNavigator.setScrollPivotX(0.15f);        commonNavigator.setAdapter(new CommonNavigatorAdapter() {            @OverrIDe            public int getCount() {                return mDataList == null ? 0 : mDataList.size();            }            @OverrIDe            public IPagerTitleVIEw getTitleVIEw(Context context, final int index) {                SimplePagerTitleVIEw simplePagerTitleVIEw = new SimplePagerTitleVIEw(context);                simplePagerTitleVIEw.setText(mDataList.get(index));                simplePagerTitleVIEw.setnormalcolor(color.parsecolor("#333333"));                simplePagerTitleVIEw.setSelectedcolor(color.parsecolor("#e94220"));                simplePagerTitleVIEw.setonClickListener(new VIEw.OnClickListener() {                    @OverrIDe                    public voID onClick(VIEw v) {                        mVIEwPager.setCurrentItem(index);                    }                });                return simplePagerTitleVIEw;            }            @OverrIDe            public IPagerIndicator getIndicator(Context context) {                TriangularPagerIndicator indicator = new TriangularPagerIndicator(context);                indicator.setlinecolor(color.parsecolor("#e94220"));                return indicator;            }        });        magicIndicator.setNavigator(commonNavigator);        VIEwPagerHelper.bind(magicIndicator, mVIEwPager);    }
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:orIEntation="vertical">    <ScrollVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="0dp"        androID:layout_weight="1"        androID:fadeScrollbars="false">        <linearLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:orIEntation="vertical">            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator1"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator2"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator3"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator4"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator5"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator6"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator7"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator8"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />            <net.lucode.Hackware.magicindicator.MagicIndicator                androID:ID="@+ID/magic_indicator9"                androID:layout_wIDth="match_parent"                androID:layout_height="@dimen/dp45"                androID:layout_margintop="@dimen/dp5" />        </linearLayout>    </ScrollVIEw>    <androIDx.vIEwpager.Widget.VIEwPager        androID:ID="@+ID/vIEw_pager"        androID:layout_wIDth="match_parent"        androID:layout_height="100dp" /></linearLayout>

 

 

总结

以上是内存溢出为你收集整理的Android MagicIndicator 指示器 导航全部内容,希望文章能够帮你解决Android MagicIndicator 指示器 导航所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1031844.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存