Skip to content

Commit

Permalink
add wrap content and full titles
Browse files Browse the repository at this point in the history
  • Loading branch information
pamepros committed Nov 7, 2013
1 parent 8cd549f commit be459e5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions library/src/com/viewpagerindicator/TabPageIndicator.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class TabPageIndicator extends HorizontalScrollView implements PageIndica
/** Title text used when no title is provided by the adapter. */
private static final CharSequence EMPTY_TITLE = "";

/** Option to wrap title and get full length titles */
private boolean wrapTitle = false;

/**
* Interface for a callback when the selected tab has been reselected.
*/
Expand Down Expand Up @@ -160,7 +163,11 @@ private void addTab(int index, CharSequence text, int iconResId) {
tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
}

mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
if(wrapTitle){
mTabLayout.addView(tabView, new LinearLayout.LayoutParams(WRAP_CONTENT, MATCH_PARENT, 1));
}else{
mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}
}

@Override
Expand Down Expand Up @@ -258,6 +265,10 @@ public void setOnPageChangeListener(OnPageChangeListener listener) {
mListener = listener;
}

public void setWrapTabTitle(boolean option){
this.wrapTitle = option;
}

private class TabView extends TextView {
private int mIndex;

Expand All @@ -270,7 +281,7 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

// Re-measure if we went beyond our maximum size.
if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) {
if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth && !wrapTitle) {
super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxTabWidth, MeasureSpec.EXACTLY),
heightMeasureSpec);
}
Expand All @@ -279,5 +290,6 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
public int getIndex() {
return mIndex;
}

}
}

0 comments on commit be459e5

Please sign in to comment.