简体   繁体   English

如何在Android的标签小部件中添加间距?

[英]How to add spacing to tab widget in Android?

I'd like to add extra spacing on the sides and between tabs on the tab widget, but padding and margins dont seem to make any difference. 我想在标签小部件的侧面和标签之间添加额外的间距,但是填充和边距似乎没有任何区别。 I also played with setting the divider, tab strip left and right drawables, which didn't seem to make any difference either. 我还设置了分隔线,标签条左右绘制对象,这似乎也没有任何区别。

Trying to make the tabs look like this: 试图使选项卡看起来像这样: 替代文字

You can use this code to do that 您可以使用此代码来做到这一点

TabWidget widget = getTabWidget();
final int tabChildrenCount = widget.getChildCount();
LinearLayout.LayoutParams currentLayout;
for (int i = 0; i < tabChildrenCount; i++) {
    currentLayout = (LinearLayout.LayoutParams) widget.getChildAt(i).getLayoutParams();
    if (i == 0) {
        currentLayout.setMargins(10, 0, 5, 0);
    } else if (i == (tabChildrenCount - 1)) {
        currentLayout.setMargins(5, 0, 10, 0);
    } else {
        currentLayout.setMargins(5, 0, 5, 0);
    }
    currentLayout.height = 40;
}
widget.requestLayout();

You need to set the divider between the Tab widgets. 您需要在Tab小部件之间设置分隔线。 Take a look at dividers between TabWidgets 看看TabWidgets之间的分隔线

The Google IO schedule app has tabs that look just like yours. Google IO时间表应用程序具有与您的外观相似的标签。 I would check out that app and browse their source code: http://code.google.com/p/iosched/ (the middle screenshot has the tabs) 我将检查该应用程序并浏览其源代码: http : //code.google.com/p/iosched/ (中间的屏幕截图包含标签)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM