Skip to content
This repository has been archived by the owner on Apr 19, 2018. It is now read-only.

fix bug:Title can't show completed while use paddingLeft or paddingRi… #363

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion library/src/com/viewpagerindicator/TabPageIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.viewpagerindicator;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
Expand Down Expand Up @@ -51,6 +52,17 @@ public interface OnTabReselectedListener {
}

private Runnable mTabSelector;

private int mPaddingLeft;
private int mPaddingRight;

private static final int[] ATTRS = new int[]{
android.R.attr.paddingLeft,
android.R.attr.paddingRight
};

private static final int ATTR_PADDING_LEFT = 0;
private static final int ATTR_PADDING_RIGHT = 1;

private final OnClickListener mTabClickListener = new OnClickListener() {
public void onClick(View view) {
Expand Down Expand Up @@ -82,6 +94,11 @@ public TabPageIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
setHorizontalScrollBarEnabled(false);

TypedArray typedArray = context.obtainStyledAttributes(attrs, ATTRS, R.attr.vpiTabPageIndicatorStyle, 0);
mPaddingLeft = typedArray.getDimensionPixelSize(ATTR_PADDING_LEFT, 0);
mPaddingRight = typedArray.getDimensionPixelSize(ATTR_PADDING_RIGHT, 0);
typedArray.recycle();

mTabLayout = new IcsLinearLayout(context, R.attr.vpiTabPageIndicatorStyle);
addView(mTabLayout, new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT));
}
Expand All @@ -99,7 +116,7 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int childCount = mTabLayout.getChildCount();
if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
if (childCount > 2) {
mMaxTabWidth = (int)(MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
mMaxTabWidth = (int)(mPaddingLeft + mPaddingRight + MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
} else {
mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
}
Expand Down