开发者

How can I set the tab height in a layout XML file?

开发者 https://www.devze.com 2023-03-21 03:18 出处:网络
I used to use : tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =50; to set my tab height.

I used to use :

tabHost.getTabWidget().getChildAt(0).getLayoutParams().height =50;

to set my tab height.

But I would like to move this tab height setting from Java code to layout xml files with the purpose to use different height value for layout/main.xml and layout-large/main.xml

My question is how to set tab height in xml file?

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <T开发者_Go百科abWidget
                android:id="@android:id/tabs"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">


        </FrameLayout>
      </LinearLayout>
</TabHost>


you can specify the height of tab in dip what ever you need. You can either use the Property window or directly given in .Xml file.

          <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="50dip" />


In additional to set height in xml

<TabWidget
            android:id="@android:id/tabs"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="@dimen/tab_height" />

I also made some actions in code

int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, res.getDimension(R.dimen.tab_height), res.getDisplayMetrics());
    for (int i=0; i<mTabHost.getTabWidget().getTabCount(); i++)
    {
        mTabHost.getTabWidget().getChildAt(i).getLayoutParams().height = height;
    }

This make tab height and position of blue strip line correct. Without java code blue line may appears over stretched tabs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号