2

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: alt text

Eno
  • 10,730
  • 18
  • 53
  • 86

3 Answers3

5

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();
user1752772
  • 51
  • 1
  • 2
1

You need to set the divider between the Tab widgets. Take a look at dividers between TabWidgets

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Yes, I *am* setting the divider in the layout XML but it doesn't seem to work. Ill try doing it programmatically as your link suggests. Thanks. – Eno Nov 13 '10 at 10:44
1

The Google IO schedule app has tabs that look just like yours. I would check out that app and browse their source code: http://code.google.com/p/iosched/ (the middle screenshot has the tabs)

Josh Clemm
  • 2,966
  • 20
  • 21
  • Good call - that's a neat looking app and reading the source is very instructive so thanks for the pointer. – Eno Nov 13 '10 at 10:48