List of usage examples for android.content.res TypedArray getDimension
public float getDimension(@StyleableRes int index, float defValue)
From source file:com.github.segoh.viewpagerindicator.ViewPagerIndicator.java
public ViewPagerIndicator(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); if (isInEditMode()) { return;//ww w . j ava 2 s . c o m } final Resources res = getResources(); final int defaultCurrentPageColor = res.getColor(R.color.vpi__current_page); final int defaultPageColor = res.getColor(R.color.vpi__page); final float defaultRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, res.getDisplayMetrics()); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPagerIndicator, defStyleAttr, 0); if (a != null) { mPaintPage.setStyle(Paint.Style.FILL); mPaintPage.setColor(a.getColor(R.styleable.ViewPagerIndicator_pageColor, defaultPageColor)); mPaintCurrentPage.setStyle(Paint.Style.FILL); mPaintCurrentPage .setColor(a.getColor(R.styleable.ViewPagerIndicator_currentPageColor, defaultCurrentPageColor)); mRadius = a.getDimension(R.styleable.ViewPagerIndicator_radius, defaultRadius); Drawable background = a.getDrawable(R.styleable.ViewPagerIndicator_android_background); setBackgroundDrawable(background); a.recycle(); } }
From source file:com.maedi.user.godok.v1.viewpagerindicator.LinePageIndicator.java
@SuppressWarnings("deprecation") public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;// w w w .ja v a2 s . c om final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = res .getColor(com.viewpagerindicator.R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res .getColor(com.viewpagerindicator.R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res .getDimension(com.viewpagerindicator.R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res .getBoolean(com.viewpagerindicator.R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, com.viewpagerindicator.R.styleable.LinePageIndicator, defStyle, 0); mCentered = a.getBoolean(com.viewpagerindicator.R.styleable.LinePageIndicator_centered, defaultCentered); mLineWidth = a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); setStrokeWidth(a.getDimension(com.viewpagerindicator.R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected.setColor(a.getColor(com.viewpagerindicator.R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(com.viewpagerindicator.R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a .getDrawable(com.viewpagerindicator.R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.ch.ch_library.smartlayout.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);//from w w w . j av a 2s .co m setOverScrollMode(OVER_SCROLL_NEVER); final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; int textColor = TAB_VIEW_TEXT_COLOR; float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm); int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density); int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density); boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY; int textLayoutId = NO_ID; int textViewId = NO_ID; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor); textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize); textHorizontalPadding = a.getDimensionPixelSize( R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding); textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth); textLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, textLayoutId); textViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, textViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); a.recycle(); mTitleOffset = (int) (TITLE_OFFSET_DIPS * density); mTabViewTextAllCaps = textAllCaps; mTabViewTextColor = textColor; mTabViewTextSize = textSize; mTabViewTextHorizontalPadding = textHorizontalPadding; mTabViewTextMinWidth = textMinWidth; mTabViewLayoutId = textLayoutId; mTabViewTextViewId = textViewId; mDistributeEvenly = distributeEvenly; mTabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }
From source file:com.github.antoniodisanto92.swipeselector.SwipeSelector.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeSelector, defStyleAttr, defStyleRes);/* ww w . j a v a2 s . com*/ int indicatorSize; int indicatorMargin; int indicatorInActiveColor; int indicatorActiveColor; int leftButtonResource; int rightButtonResource; String customFontPath; int titleTextAppearance; int descriptionTextAppearance; int descriptionGravity; try { indicatorSize = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorSize, PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_SIZE)); indicatorMargin = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorMargin, PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_MARGIN)); indicatorInActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorInActiveColor, ContextCompat.getColor(context, R.color.swipeselector_color_indicator_inactive)); indicatorActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorActiveColor, ContextCompat.getColor(context, R.color.swipeselector_color_indicator_active)); leftButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_leftButtonResource, R.drawable.ic_action_navigation_chevron_left); rightButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_rightButtonResource, R.drawable.ic_action_navigation_chevron_right); customFontPath = ta.getString(R.styleable.SwipeSelector_swipe_customFontPath); titleTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_titleTextAppearance, -1); descriptionTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_descriptionTextAppearance, -1); descriptionGravity = ta.getInteger(R.styleable.SwipeSelector_swipe_descriptionGravity, -1); } finally { ta.recycle(); } LayoutInflater inflater = LayoutInflater.from(context); inflater.inflate(R.layout.swipeselector_layout, this); ViewPager pager = (ViewPager) findViewById(R.id.swipeselector_layout_swipePager); ViewGroup indicatorContainer = (ViewGroup) findViewById(R.id.swipeselector_layout_circleContainer); ImageView leftButton = (ImageView) findViewById(R.id.swipeselector_layout_leftButton); ImageView rightButton = (ImageView) findViewById(R.id.swipeselector_layout_rightButton); mAdapter = new SwipeAdapter.Builder().viewPager(pager).indicatorContainer(indicatorContainer) .indicatorSize(indicatorSize).indicatorMargin(indicatorMargin) .inActiveIndicatorColor(indicatorInActiveColor).activeIndicatorColor(indicatorActiveColor) .leftButtonResource(leftButtonResource).rightButtonResource(rightButtonResource) .leftButton(leftButton).rightButton(rightButton).customFontPath(customFontPath) .titleTextAppearance(titleTextAppearance).descriptionTextAppearance(descriptionTextAppearance) .descriptionGravity(descriptionGravity).build(); pager.setAdapter(mAdapter); }
From source file:com.aksalj.viewpagerslideshow.LinePageIndicator.java
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return;//from w w w .j a va 2 s. com final Resources res = getResources(); //Load defaults from resources final int defaultLineStyle = res.getInteger(R.integer.default_line_style); final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); mBoxStyle = a.getInt(R.styleable.LinePageIndicator_lineStyle, defaultLineStyle) == 1; mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, mBoxStyle ? false : defaultCentered); mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, mBoxStyle ? 0.0f : defaultGapWidth); setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background); if (background != null) { setBackgroundDrawable(background); } a.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.tomeokin.widget.jotablayout2.JoTabLayout.java
public JoTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setWillNotDraw(false); // ? onMeasure ?? onDraw ? setClipChildren(false);/*w ww .j a va 2 s .c om*/ setClipToPadding(false); // obtain user defined attr values TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.JoTabLayout, defStyleAttr, 0); // underline mUnderlineColor = a.getColor(R.styleable.JoTabLayout_underlineColor, mUnderlineColor); mUnderlineHeight = a.getDimension(R.styleable.JoTabLayout_underlineHeight, mUnderlineHeight); mUnderlineGravity = a.getInt(R.styleable.JoTabLayout_underlineGravity, mUnderlineGravity); // divider mDividerColor = a.getColor(R.styleable.JoTabLayout_dividerColor, mDividerColor); mDividerWidth = a.getDimension(R.styleable.JoTabLayout_dividerWidth, mDividerWidth); mDividerVerticalPadding = a.getDimensionPixelSize(R.styleable.JoTabLayout_dividerVerticalPadding, mDividerVerticalPadding); // indicator mIndicatorShape = a.getInt(R.styleable.JoTabLayout_indicatorShape, mIndicatorShape); // init default indicator attrs again according to mIndicatorShape if (mIndicatorShape == SHAPE_TRIANGLE) { mIndicatorWidth = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10, getResources().getDisplayMetrics()); mIndicatorHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3, getResources().getDisplayMetrics()); } else { mIndicatorWidth = 0; mIndicatorHeight = 0; } mIndicatorColor = (mIndicatorShape == SHAPE_SQUARE) ? Color.parseColor("#e0e0e0") : Color.parseColor("#0277bd"); mIndicatorColor = a.getColor(R.styleable.JoTabLayout_indicatorColor, mIndicatorColor); mIndicatorWidth = a.getDimension(R.styleable.JoTabLayout_indicatorWidth, mIndicatorWidth); mIndicatorHeight = a.getDimension(R.styleable.JoTabLayout_indicatorHeight, mIndicatorHeight); mIndicatorCornerRadius = a.getDimension(R.styleable.JoTabLayout_indicatorCornerRadius, mIndicatorCornerRadius); mIndicatorGravity = a.getInt(R.styleable.JoTabLayout_indicatorGravity, mIndicatorGravity); mIndicatorAnimDuration = a.getInt(R.styleable.JoTabLayout_indicatorAnimDuration, mIndicatorAnimDuration); mIndicatorAnimEnabled = a.getBoolean(R.styleable.JoTabLayout_indicatorAnimEnabled, mIndicatorAnimEnabled); mIndicatorBounceEnabled = a.getBoolean(R.styleable.JoTabLayout_indicatorBounceEnabled, mIndicatorBounceEnabled); a.recycle(); mValueAnimator = ValueAnimator.ofObject(new PointEvaluator(), mLastP, mCurrentP); mValueAnimator.addUpdateListener(this); }
From source file:com.threehalf.tucao.view.pageindicator.TabPageIndicator.java
public TabPageIndicator(Context context, AttributeSet attrs) { super(context, attrs); final Resources res = getResources(); // final int textColor = // res.getres(R.color.default_tab_indicator_text_color); final int tabSelectedColor = res.getColor(R.color.default_tab_indicator_selected_color); final int tabUnSelectedColor = res.getColor(R.color.default_tab_indicator_unselected_color); final float textSize = res.getDimension(R.dimen.default_tab_indicator_textsize); final float paddingLeft = res.getDimension(R.dimen.default_tab_indicator_paddingleft); final float paddingRight = res.getDimension(R.dimen.default_tab_indicator_paddingright); final float paddingTop = res.getDimension(R.dimen.default_tab_indicator_paddingtop); final float paddingBottom = res.getDimension(R.dimen.default_tab_indicator_paddingbottom); final float tabSelectedHeight = res.getDimension(R.dimen.default_tab_indicator_selected_height); final float tabUnSelectedHeight = res.getDimension(R.dimen.default_tab_indicator_unselected_height); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator); mTextColor = a.getResourceId(R.styleable.TabPageIndicator_textColor, R.drawable.selector_tabtextcolor); mTabSelectedColor = a.getColor(R.styleable.TabPageIndicator_selectedColor, tabSelectedColor); mTabUnSelectedColor = a.getColor(R.styleable.TabPageIndicator_unselectedColor, tabUnSelectedColor); mTextSize = a.getDimension(R.styleable.TabPageIndicator_textSize, textSize); mPaddingLeft = a.getDimension(R.styleable.TabPageIndicator_paddingLeft, paddingLeft); mPaddingRight = a.getDimension(R.styleable.TabPageIndicator_paddingRight, paddingRight); mPaddingTop = a.getDimension(R.styleable.TabPageIndicator_paddingTop, paddingTop); mPaddingBottom = a.getDimension(R.styleable.TabPageIndicator_paddingBottom, paddingBottom); mTabSelectedHeight = a.getDimension(R.styleable.TabPageIndicator_selectedHeight, tabSelectedHeight); mTabUnSelectedHeight = a.getDimension(R.styleable.TabPageIndicator_unSelectedHeight, tabUnSelectedHeight); setHorizontalScrollBarEnabled(false); mTabAndIndicator = new LinearLayout(context); mTabAndIndicator.setOrientation(LinearLayout.VERTICAL); mTabLayout = new LinearLayout(context); mTabAndIndicator.addView(mTabLayout, new LinearLayout.LayoutParams(WRAP_CONTENT, 0, 1)); mSlideLineIndicator = new SlideLineIndicator(context); mTabAndIndicator.addView(mSlideLineIndicator, new LinearLayout.LayoutParams(MATCH_PARENT, (int) mTabSelectedHeight, 0)); addView(mTabAndIndicator, new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT)); a.recycle();//from w w w. j a va 2 s . co m }
From source file:com.example.anumbrella.viewpager.LinePagerIndicator.java
public LinePagerIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); ///*from ww w . j a va2 s . co m*/ if (isInEditMode()) { return; } //?? final Resources res = getResources(); // //? final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); // final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); // final float defalutLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); //? final float defalutGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); // final float defalutStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); //?? final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //xml TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.LinePagerIndicator, defStyle, 0); mCentered = array.getBoolean(R.styleable.LinePagerIndicator_centered, defaultCentered); mLineWidth = array.getDimension(R.styleable.LinePagerIndicator_lineWidth, defalutLineWidth); mGapWidth = array.getDimension(R.styleable.LinePagerIndicator_gapWidth, defalutGapWidth); //? setStrokeWidth(array.getDimension(R.styleable.LinePagerIndicator_strokeWidth, defalutStrokeWidth)); mPaintUnselected .setColor(array.getColor(R.styleable.LinePagerIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(array.getColor(R.styleable.LinePagerIndicator_selectedColor, defaultSelectedColor)); Drawable background = array.getDrawable(R.styleable.LinePagerIndicator_android_background); // if (background != null) { setBackgroundDrawable(background); } array.recycle(); final ViewConfiguration configuration = ViewConfiguration.get(context); //????(?????) mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); }
From source file:com.example.roman.paralaxlv.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);//w w w . ja v a2 s .c o m setWillNotDraw(false); tabsContainer = new LinearLayout(context); tabsContainer.setOrientation(LinearLayout.HORIZONTAL); tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(tabsContainer); DisplayMetrics dm = getResources().getDisplayMetrics(); scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm); indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm); underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm); dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm); tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm); dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm); tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm); // get system attrs (android:textSize and android:textColor) TypedArray a = context.obtainStyledAttributes(attrs, ATTRS); tabTextSize = a.getDimensionPixelSize(0, tabTextSize); tabTextColor = a.getColor(1, tabTextColor); a.recycle(); // get custom attrs a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor); underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor); dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor); indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, indicatorHeight); underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, underlineHeight); dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, dividerPadding); tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding); tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId); shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand); scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset); textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps); a.recycle(); rectPaint = new Paint(); rectPaint.setAntiAlias(true); rectPaint.setStyle(Style.FILL); dividerPaint = new Paint(); dividerPaint.setAntiAlias(true); dividerPaint.setStrokeWidth(dividerWidth); defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); if (locale == null) { locale = getResources().getConfiguration().locale; } final TypedArray styledAttributes = getContext().getTheme() .obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); mActionBarHeight = (int) styledAttributes.getDimension(0, 0) + 15; styledAttributes.recycle(); }
From source file:com.shichai.www.choume.view.tab.SmartTabLayout.java
public SmartTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);/* ww w .j av a 2 s . com*/ final DisplayMetrics dm = getResources().getDisplayMetrics(); final float density = dm.density; boolean textAllCaps = TAB_VIEW_TEXT_ALL_CAPS; int textColor = TAB_VIEW_TEXT_COLOR; float textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP, dm); int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density); int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density); boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY; int customTabLayoutId = NO_ID; int customTabTextViewId = NO_ID; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0); textAllCaps = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_defaultTabTextAllCaps, textAllCaps); textColor = a.getColor(R.styleable.stl_SmartTabLayout_stl_defaultTabTextColor, textColor); textSize = a.getDimension(R.styleable.stl_SmartTabLayout_stl_defaultTabTextSize, textSize); textHorizontalPadding = a.getDimensionPixelSize( R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding); textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth, textMinWidth); customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId, customTabLayoutId); customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId, customTabTextViewId); distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly); a.recycle(); mTitleOffset = (int) (TITLE_OFFSET_DIPS * density); mTabViewTextAllCaps = textAllCaps; mTabViewTextColor = textColor; mTabViewTextSize = textSize; mTabViewTextHorizontalPadding = textHorizontalPadding; mTabViewTextMinWidth = textMinWidth; mDistributeEvenly = distributeEvenly; if (customTabLayoutId != NO_ID) { setCustomTabView(customTabLayoutId, customTabTextViewId); } mTabStrip = new SmartTabStrip(context, attrs); if (distributeEvenly && mTabStrip.isIndicatorAlwaysInCenter()) { throw new UnsupportedOperationException( "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support"); } addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); }