【问题标题】:TAB Layout WidthTAB 布局宽度
【发布时间】:2011-06-21 16:15:02
【问题描述】:

我卡在我的 xml 代码中

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

我正在尝试将宽度更改为自定义设置的倾角,但是

android:layout_width="50dip"

对标签宽度布局没有任何影响 请问这个有什么建议吗?

这是 pasteBin 上的完整 XML 文件布局

http://pastebin.com/7vi4Pi8Z

谢谢 设拉子

【问题讨论】:

    标签: java android xml tabs tabwidget


    【解决方案1】:

    没有人提供答案,但经过几个小时的努力,我找到了解决方法 在java代码中设置标签的宽度... 给你,如果以后有人需要这个

    TabWidget tabWidget = (TabWidget) findViewById(android.R.id.tabs);
    final int tabChildrenCount = tabWidget.getChildCount();
    for (int i=0; i< tabChildrenCount; i++)
    {
            // change the value 110 to whatever suits you for tab width
        tHost.getTabWidget().getChildAt(i).getLayoutParams().width = 110;
    }
    

    非常感谢 设拉子

    【讨论】:

      【解决方案2】:

      如果您不需要每个标签的大小不同,那么最简单的宽度缩减可能是添加类似

      android:weightSum="5"
      

      到您的 TabWidget 参数。

      【讨论】:

        猜你喜欢
        • 2016-05-22
        • 1970-01-01
        • 2016-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多