Android - 如何设置tabWidget的重力?

时间:2014-04-16 09:55:38

标签: android gravity tabwidget fragment-tab-host

我创建了一个FragmentTabHost并且它可以正常工作,但我想将制表符的重力设置为正确。我使用了这段代码,但它不起作用:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.RIGHT;
mTabHost.getTabWidget().setLayoutParams(params);

我的XML布局文件如下:

<android.support.v4.app.FragmentTabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >    
    <TabWidget
        android:id="@android:id/tabs"
        android:gravity="right"
        android:layout_gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</android.support.v4.app.FragmentTabHost>

任何建议都将不胜感激!

1 个答案:

答案 0 :(得分:0)

请更改为此代码。

<TabWidget
        android:id="@android:id/tabs"
        android:gravity="right"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

不需要以编程方式编写代码。