How can I set the height of tabs in Android a TabLayout?

前端 未结 3 1056
孤独总比滥情好
孤独总比滥情好 2021-01-12 06:37

I Have this TabLayout in Android and wanted to make the tabs a little heigher than the default (48dp)

    

        
相关标签:
3条回答
  • 2021-01-12 06:47

    I use the following code for setting the height of TabLayout. Hope it helps you:

    //Get tablayout
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    //Get the layout params that will allow you to resize the tablayout
    ViewGroup.LayoutParams params = tabLayout.getLayoutParams();
    //Change the height in 'Pixels'
    params.height = 100;
    tabLayout.setLayoutParams(params);
    
    0 讨论(0)
  • 2021-01-12 06:54

    set a layout_height in dps instead of wrap_content this could differ in different display sizes but if you wanna set a height dynamically

    getApplication.getResources().getDisplayMetrics()
    

    get your current height and calculate the height according to that

    0 讨论(0)
  • 2021-01-12 07:00

    just change layout_height from wrap_content to what ever u want it to be

      <android.support.design.widget.TabLayout
                android:id="@+id/contentTabs"
                android:layout_width="match_parent"
                android:layout_height="Your Value"
                style="@style/Theme.Zhaw.TabLayout"
                app:tabMode="fixed"
                app:tabGravity="fill"/>
    
    0 讨论(0)
提交回复
热议问题