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

老子叫甜甜 提交于 2019-12-05 09:36:45
Sajidh Zahir

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

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"/>

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);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!