Skip to content

Instantly share code, notes, and snippets.

@operando
Last active September 29, 2015 08:10
Show Gist options
  • Save operando/93dbe5c940e968014d18 to your computer and use it in GitHub Desktop.
Save operando/93dbe5c940e968014d18 to your computer and use it in GitHub Desktop.
Since v23 of the support library contain a layout bug. https://code.google.com/p/android/issues/detail?id=183127 The suggested workaround is to use this Class.
package android.support.v4.view;
import android.content.Context;
import android.util.AttributeSet;
/**
* Since v23 of the support library contain a layout bug.
* https://code.google.com/p/android/issues/detail?id=183127
*/
public class CustomPagerTabStrip extends PagerTabStrip {
public CustomPagerTabStrip(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthMode != MeasureSpec.EXACTLY) {
throw new IllegalStateException("Must measure with an exact width");
}
int childHeight = heightSize;
int minHeight = getMinHeight();
int padding = 0;
padding = getPaddingTop() + getPaddingBottom();
childHeight -= padding;
final int childWidthSpec = MeasureSpec.makeMeasureSpec((int) (widthSize * 0.8f),
MeasureSpec.AT_MOST);
final int childHeightSpec = MeasureSpec.makeMeasureSpec(childHeight, MeasureSpec.AT_MOST);
mPrevText.measure(childWidthSpec, childHeightSpec);
mCurrText.measure(childWidthSpec, childHeightSpec);
mNextText.measure(childWidthSpec, childHeightSpec);
if (heightMode == MeasureSpec.EXACTLY) {
setMeasuredDimension(widthSize, heightSize);
} else {
int textHeight = mCurrText.getMeasuredHeight();
setMeasuredDimension(widthSize, Math.max(minHeight, textHeight + padding));
}
}
}
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.CustomPagerTabStrip
android:id="@+id/pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:textColor="#ff0000"/>
</android.support.v4.view.ViewPager>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment