/** * Draw divider * * @param canvas The canvas */ private void drawDivider(Canvas canvas) { if (mShowDivider) { final int childCount = getChildCount(); final int height = getHeight() - mDividerPaddingTop - mDividerPaddingBottom; for (int i = 0; i < childCount - 1; i++) { final View child = getChildAt(i); mDividerPaint.setColor(mTabStripColorize.getDividerColor(i)); canvas.drawLine( child.getRight() + mDividerPaddingLeft, mDividerPaddingTop, child.getRight() + mDividerPaddingLeft, mDividerPaddingTop + height, mDividerPaint); } } }
/** * Draw indicator * * @param canvas The canvas */ private void drawIndicator(Canvas canvas) { if (mShowIndicator) { final int height = getHeight(); final int childCount = getChildCount(); if (childCount > 0) { View tabView = getChildAt(mSelectedPosition); int left = tabView.getLeft(); int right = tabView.getRight(); int color = mTabStripColorize.getIndicatorColor(mSelectedPosition); if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) { int nextColor = mTabStripColorize.getIndicatorColor(mSelectedPosition + 1); if (color != nextColor) { color = ColorUtils.blendColors(nextColor, color, mSelectionOffset); } // Draw the selection partway between the tabs View nextTabView = getChildAt(mSelectedPosition + 1); left = (int) (mSelectionOffset * nextTabView.getLeft() + (1.0f - mSelectionOffset) * left); right = (int) (mSelectionOffset * nextTabView.getRight() + (1.0f - mSelectionOffset) * right); } mIndicatorPaint.setColor(color); RectF rectF = new RectF( left, height - mIndicatorHeight - mIndicatorPaddingBottom, right, height - mIndicatorPaddingBottom); switch (mIndicatorGravity) { case TOP: { rectF.set(left, mIndicatorPaddingTop, right, mIndicatorHeight + mIndicatorPaddingTop); break; } case CENTER: { rectF.set( left, (height - mIndicatorHeight) / 2, right, (height + mIndicatorHeight) / 2); break; } } if (mIndicatorCornerRadius > 0f) { mIndicatorPaint.setAntiAlias(true); canvas.drawRoundRect( rectF, mIndicatorCornerRadius, mIndicatorCornerRadius, mIndicatorPaint); } else { mIndicatorPaint.setAntiAlias(false); canvas.drawRect(rectF, mIndicatorPaint); } if (mOnIndicatorColorChangedListener != null) { mOnIndicatorColorChangedListener.onIndicatorColorChanged( (NiceTabLayout) this.getParent(), color); } } } }