2015-08-21 95 views
1

我试图实现我的设计师为我设计的设计。选项卡之间的间距TabPageIndicator

我无法将compoundDrawable移近文本(设置padding属性可以将它移动很远,但即使0dp也不会使其关闭),并且我无法使制表符间的间距为固定宽度。

Tabs design

这是我得到什么(不看字体,文本颜色,强调规模,目前正在开发中):

enter image description here

但我已经对定制杰克的满足烦恼沃顿library

这里几乎是同样的问题:Space between elements of the indicator

<style name="SkillsPageIndicator" parent="Widget.TabPageIndicator"> 
     <item name="android:background">@drawable/tab_underline_indicator</item> 
     <item name="android:textSize">@dimen/text_size_medium</item> 
     <item name="android:paddingTop">35dp</item> 
     <item name="android:paddingBottom">16dp</item> 
     <item name="android:drawablePadding">0dp</item> 
     <item name="android:gravity">center</item> 
     <item name="android:width">100dp</item> 
</style> 

回答

1

我已经做得不那么干净的代码,但它适用于我。我在这里分享它来帮助任何人,谁需要它:

done image

更改密码在TabPageIndicator.addTab:

private void addTab(int index, CharSequence text, int iconResId) { 
     final TabView tabView = new TabView(getContext()); 
     tabView.mIndex = index; 
     tabView.setFocusable(true); 
     tabView.setOnClickListener(mTabClickListener); 
     tabView.setText(text); 

     /** 
     * My parts (CullyCross): 
     */ 

     Resources r = getResources(); 
     DisplayMetrics metrics = r.getDisplayMetrics(); 
     float screenWidth = metrics.widthPixels; 

     float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, metrics); 
     int margin = (int)(screenWidth - 2 * width)/4; 

     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int)width, MATCH_PARENT); 
     params.setMargins(margin, 0, margin, 0); 


     /***********************/ 

     if (iconResId != 0) { 
      tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); 
     } 

     /** 
     * original 
     * mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1)); 
     */ 

     mTabLayout.addView(tabView, params); 
    } 

随着thiner字体看起来会更好。

相关问题