How to manage the width of ActionBar navigation tabs?

前端 未结 3 1608
攒了一身酷
攒了一身酷 2021-02-05 10:48

I am using ActionBarSherlock and have an ActionBar with navigation tabs in it. I want the tabs to auto-size based on the size of the text in them, but there seems to be a style

3条回答
  •  逝去的感伤
    2021-02-05 11:16

    From that screen shot it looks like you are testing on ICS which is good since you will be observing the behavior of the native action bar rather than think it is a bug with ActionBarSherlock.

    Basically the action bar will attempt to expand tabs to take up an equal amount of space if there is enough room to do so in order to provide a cleaner look when there are only a few tabs.

    By setting the actionBarTabTextStyle padding to zero you are actually making the problem worse since now the text in the first tab has nothing around it to prevent it from touching the dividers and edge of screen. If you increase the padding (or return it to default) you should see one of two things:

    1. The text will wrap to two lines.
    2. The tab bar will convert tabs to simply be as wide as their content and allow for horizontal scrolling.

    I'm inclined to think that the former will happen due to the very thin widths of your second through fourth tab. Unfortunately this is just how the tab bar behaves and we need to just try an accomodate its behavior accordingly.

    If possible, try to create tab labels that have a more unified width which will likely trigger the second state mentioned above. Keep testing with ICS so that you can ensure the behavior you're seeing is from the platform and then when running on pre-ICS you should get the same behavior from the library.

提交回复
热议问题