2017-02-09 37 views
1

對於選項卡布局,正在對自定義佈局進行充氣custom_tab.xml,其中徽章視圖在名稱長度增加時被切斷。自定義tabLayout徽章視圖正在切斷[Android]

我已經試過WRAP_CONTENT所有視圖,仍然沒有效果

這是custom_tab.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="wrap_content" 
       android:layout_height="48dp" 
       android:layout_margin="5dp" 
       android:orientation="horizontal"> 

    <TextView 

     android:id="@+id/tv_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:gravity="center" 
     android:text="title" 
     android:textColor="@color/white" 
     android:textSize="20sp" 
     android:textStyle="bold" /> 

    <TextView 

     android:id="@+id/tv_count" 
     android:layout_width="31dp" 
     android:layout_height="31dp" 
     android:layout_gravity="center" 
     android:layout_margin="5dp" 
     android:background="@drawable/badge_drawable" 
     android:gravity="center" 
     android:textColor="#000000" 
     android:textSize="12sp" /> 

</LinearLayout> 

這是充氣的意見tablayout

private void setupTabIcons() { 
    for (int i = 0; i < NewFragment.categories.size(); i++) { 
     try { 
      LinearLayout currentTabLayout = (LinearLayout) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); 

      .............................. 
      .............................. 

      tabLayout.getTabAt(i).setCustomView(currentTabLayout); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 
} 
Java代碼

將單行設置爲長度增加的文本的屏幕快照假

屏幕截圖的文字已經增加長度設置爲真

enter image description here

單行這兩種情況下,削減從我希望文本視圖佈局 徽章視圖是單線。

誰能幫我解決這個問題。

任何形式的幫助或建議將不勝感激。

感謝

+1

嗨,Sanoop你可以嘗試修復該問題使用「選取框」屬性設置爲1行,因爲你的文字很長 –

+0

@DileepPatel感謝您的答覆,我都試過,但對徽章來看,它仍然從視圖 – Sanoop

+0

隱藏我想,如果文本太長,以適應這是不可能的影響不大,選項卡布局將嘗試適合3個選項卡,如果模式設置爲「固定」,我不得不將文本縮小爲t他同樣的要求 –

回答

0

通過在標籤下dimens.xml設置寬度到一個更高的水平文件

<dimen name="tab_max_width">XXXdp</dimen>