Skip to content

Instantly share code, notes, and snippets.

@elsennov
Last active March 20, 2016 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsennov/398aa8f62c2d244923f6 to your computer and use it in GitHub Desktop.
Save elsennov/398aa8f62c2d244923f6 to your computer and use it in GitHub Desktop.
package com.novraditya.elsen.tablayoutexample;
import android.content.Context;
import android.support.design.widget.TabLayout;
import android.util.AttributeSet;
import java.lang.reflect.Field;
/**
* Created by elsennovraditya on 3/20/16.
*/
public class CustomTabLayout extends TabLayout {
private static final int WIDTH_INDEX = 0;
private static final int DIVIDER_FACTOR = 3;
private static final String SCROLLABLE_TAB_MIN_WIDTH = "mScrollableTabMinWidth";
public CustomTabLayout(Context context) {
super(context);
initTabMinWidth();
}
public CustomTabLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initTabMinWidth();
}
public CustomTabLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTabMinWidth();
}
private void initTabMinWidth() {
int[] wh = Utils.getScreenSize(getContext());
int tabMinWidth = wh[WIDTH_INDEX] / DIVIDER_FACTOR;
Field field;
try {
field = TabLayout.class.getDeclaredField(SCROLLABLE_TAB_MIN_WIDTH);
field.setAccessible(true);
field.set(this, tabMinWidth);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment