【问题标题】:Android - How to set gravity of tabWidget?Android - 如何设置 tabWidget 的重力?
【发布时间】:2014-04-16 09:55:38
【问题描述】:

我创建了一个 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>

任何建议将不胜感激!

【问题讨论】:

    标签: android gravity tabwidget fragment-tab-host


    【解决方案1】:

    请改成这个代码。

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

    不需要编程代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 2013-04-02
      • 2021-02-15
      相关资源
      最近更新 更多