簡體   English   中英

如何在Tab布局中設置Tab寬度?

[英]How to set Tab width in Tab layout?

我正在嘗試創建一個包含兩個tabstab layout 當我在小型移動設備上運行應用程序時, tab layout看起來不錯,但是當我在Tablet上運行相同的應用程

在平板電腦上看起來像這樣:

在此輸入圖像描述

我希望每個標簽占據整個空間,兩端都沒有任何間隙。 我已經創建了這樣的tab layout ......

private void drawTabLayout() {
    tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.addTab(tabLayout.newTab().setText("Imprint") );
    tabLayout.addTab(tabLayout.newTab().setText("Legal"));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
    tabLayout.setTabMode(TabLayout.MODE_FIXED);
    tabLayout.setSelectedTabIndicatorHeight(10);
    tabLayout.setBackgroundColor(Color.WHITE);
}

我搜索了很多網站但找不到合適的答案

tab_layout.xml添加此代碼

<android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMaxWidth="0dp"
            app:tabGravity="fill"
            app:tabMode="fixed" />

希望它對你有用......

您可以創建一個選項卡布局,其中每個選項卡都有一個自定義視圖,並在tablayout中添加該選項卡,無論您選擇何種大小

View customView = LayoutInflater.from(getContext()).inflate(R.layout.tab_text, null); 

addTab(newTab().setCustomView(customView))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM