如何管理ActionBar的导航标签的宽度是多少? [英] How to manage the width of ActionBar navigation tabs?

查看:514
本文介绍了如何管理ActionBar的导航标签的宽度是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ActionBarSherlock,并与导航标签在它的动作条。我想标签基于其中的文本的大小自动调整大小,但似乎有一种风格,或迫使他们使用的最小尺寸的设定地方。因此,例如在截图选项卡甚长标签无填充(按照我申请的造型),但标签标有T有大量的填充物,尽管我设置填充到0dp。

正如你可以看到下面我试图通过设置几个风格不同的属性蛮力的方式,但我没有成功过。

我如何控制填充/宽度操作栏中的标签?

 <风格
    NAME =CustomActivity
    父=@风格/ Theme.Sherlock
    >
    <项目名称=actionBarTabStyle> @风格/ customActionBarTabStyle< /项目>
    <项目名称=actionBarTabBarStyle> @风格/ customActionBarTabBarStyle< /项目>
    <项目名称=actionBarTabTextStyle> @风格/ customActionBarTabTextStyle< /项目>
< /风格>

<样式名称=customActionBarTabStyle父=风格/ Widget.Sherlock.ActionBar.TabView>
    <项目名称=机器人:背景> @可绘制/ tab_indicator< /项目>
    <项目名称=机器人:以下属性来> 0dp< /项目>
    <项目名称=机器人:paddingRight> 0dp< /项目>
    <项目名称=机器人:layout_width> WRAP_CONTENT< /项目>
    <项目名称=安卓了minWidth> 0dp< /项目>
< /风格>

<样式名称=customActionBarTabBarStyle父=风格/ Widget.Sherlock.ActionBar.TabBar>
    <项目名称=机器人:以下属性来> 0dp< /项目>
    <项目名称=机器人:paddingRight> 0dp< /项目>
    <项目名称=机器人:layout_width> WRAP_CONTENT< /项目>
    <项目名称=安卓了minWidth> 0dp< /项目>
< /风格>

<样式名称=customActionBarTabTextStyle父=风格/ Widget.Sherlock.ActionBar.TabText>
    <项目名称=机器人:以下属性来> 0dp< /项目>
    <项目名称=机器人:paddingRight> 0dp< /项目>
    <项目名称=机器人:layout_width> WRAP_CONTENT< /项目>
    <项目名称=安卓了minWidth> 0dp< /项目>
< /风格>
 

解决方案

从该屏幕快照,它看起来像要在ICS测试这是很好的,因为你会观察本机操作栏的行为,而不是认为这是一个错误与ActionBarSherlock。

基本上,操作栏将尝试扩展卡占用的空间等量是否有足够的空间,这样做是为了当只有几个选项卡提供了简洁的外观。

通过设置 actionBarTabTextStyle 填充到零,实际上是使问题变得更糟,因为现在在第一个选项卡中的文本周围有什么可触碰prevent它分频器和屏幕的边缘。如果增加的填充(或返回到默认),你应该看到一两件事情:

  1. 在该文本将换到两行。
  2. 标签栏将标签转换成仅仅是尽可能广泛的内容,并允许水平滚动。

我倾向于认为前者会发生由于非常薄的宽度的第二至第四个选项卡。不幸的是,这是多么的标签栏的行为,我们需要只是尝试的适应其行为相应。

如果可能的话,尝试创建有一个更统一的宽度可能会引发上述第二状态选项卡的标签。保持测试与ICS这样就可以确保在pre-ICS运行时,你应该从库中相同的行为,你所看到的行为是从平台后。

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 or a setting somewhere that is forcing them to use a minimum size. So for example in the screenshot the tab "Very Long Tab" has no padding (in accordance with the styling I applied) but the tabs marked "T" have a great deal of padding, despite me setting padding to 0dp.

As you can see below I've tried a brute-force approach by setting various attributes on several styles, but I've not succeeded yet.

How do I control the padding/width in the action bar tabs?

<style
    name="CustomActivity"
    parent="@style/Theme.Sherlock"
    >
    <item name="actionBarTabStyle">@style/customActionBarTabStyle</item>
    <item name="actionBarTabBarStyle">@style/customActionBarTabBarStyle</item>
    <item name="actionBarTabTextStyle">@style/customActionBarTabTextStyle</item>
</style>

<style name="customActionBarTabStyle" parent="style/Widget.Sherlock.ActionBar.TabView">
    <item name="android:background">@drawable/tab_indicator</item>
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:minWidth">0dp</item>
</style>

<style name="customActionBarTabBarStyle" parent="style/Widget.Sherlock.ActionBar.TabBar">
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:minWidth">0dp</item>
</style>

<style name="customActionBarTabTextStyle" parent="style/Widget.Sherlock.ActionBar.TabText">
    <item name="android:paddingLeft">0dp</item>
    <item name="android:paddingRight">0dp</item>
    <item name="android:layout_width">wrap_content</item>
    <item name="android:minWidth">0dp</item>
</style>

解决方案

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.

这篇关于如何管理ActionBar的导航标签的宽度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆