简体   繁体   English

操作栏(Sherlock)菜单项切断了内置微调器

[英]Action bar (Sherlock) menu items cutting off built-in Spinner

My action bar menu items are cutting off the width of the action bar Spinner so that the Spinner's text gets truncated. 我的操作栏菜单项削减了操作栏微调器的宽度,以便微调器的文本被截断。 I've set all my menu items to use "ifRoom" but unfortunately they interpret the original Spinner width as available room. 我将所有菜单项都设置为使用“ ifRoom”,但不幸的是,它们将原始Spinner宽度解释为可用空间。

Here's the truncation when I have three menu items (yes, I know the third icon looks identical to the second): 这是我有三个菜单项时的截断(是的,我知道第三个图标看起来与第二个相同):

带截头微调器的操作栏

Here's what I get when I comment out the third menu item. 这是我注释掉第三个菜单项时得到的。 Ultimately, I want something that looks like this, but with an overflow icon showing instead of the search icon: 最终,我想要看起来像这样的东西,但是要显示一个溢出图标而不是搜索图标:

带完整微调器的操作栏,但只有两个菜单项

I populate the Spinner using a custom adapter (extending from BaseAdapter and implementing SpinnerAdapter). 我使用自定义适配器(从BaseAdapter扩展并实现SpinnerAdapter)填充Spinner。

Here's my menu XML: 这是我的菜单XML:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/ab_refresh"
        android:orderInCategory="1"
        android:showAsAction="ifRoom"
        android:title="@string/ab_refresh"
        android:icon="@drawable/navigation_refresh"/>

    <item
        android:id="@+id/ab_search"
        android:orderInCategory="2"
        android:showAsAction="ifRoom|collapseActionView"
        android:title="@string/ab_search"
        android:icon="@drawable/action_search"
        android:actionViewClass="com.actionbarsherlock.widget.SearchView"/>

    <item
        android:id="@+id/ab_toggle"
        android:orderInCategory="3"
        android:showAsAction="ifRoom"
        android:title="@string/ab_latest"
        android:icon="@drawable/action_search"/>

</menu>

And here's my ab_dropdown XML (used in getView of my custom adapter): 这是我的ab_dropdown XML(在我的自定义适配器的getView中使用):

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rel"
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:gravity="fill_horizontal">

    <TextView
        android:id="@+id/txt"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="20sp"
        android:textStyle="bold"
        android:layout_marginLeft="5dp"
        android:layout_marginTop="1dp" />

</RelativeLayout>

What I've tried: 我尝试过的

  1. Setting a minWidth of 570dp for the RelativeLayout and TextView of ab_dropdown. 为ab_dropdown的RelativeLayout和TextView设置minWidth为570dp。 No effect regardless of whether I set it in XML or the getView method of my custom adapter. 不管是在XML中还是在自定义适配器的getView方法中进行设置,都无效。
  2. Hardcoding the layout_width of RelativeLayout and TextView to 570dp. 将RelativeLayout和TextView的layout_width硬编码为570dp。 Again, no effect in XML or code. 同样,在XML或代码中无效。
  3. I WOULD attempt to find the action bar Spinner programmatically so as to set its width, but when I tried to do this for a different reason , I couldn't. 我将尝试以编程方式找到操作条Spinner以便设置其宽度,但是当我出于其他原因尝试执行此操作时 ,则无法这样做。

Any ideas? 有任何想法吗?

Personally, I'd switch to a navigation drawer and dump the drop-down list navigation. 就个人而言,我将切换到导航抽屉并转储下拉列表导航。

That being said, it sounds like you need two versions of your menu resource. 话虽如此,听起来您需要两个版本的菜单资源。 Have the third item be never in the toolbar (always in overflow) by default, and have it be ifRoom on larger screens (eg, res/menu-sw600dp/ ). 默认情况下,使第三项never ifRoom工具栏中(始终处于溢出状态),而在较大的屏幕上(例如res/menu-sw600dp/ )将其设为ifRoom

You could also experiment with AutoScaleTextView for your drop-down list navigation labels. 您还可以尝试使用AutoScaleTextView作为下拉列表导航标签。

The navigation portion of the action bar is deemed least important, which is why ifRoom considers there to be room. 操作栏的导航部分被认为是最不重要的,这就是为什么ifRoom认为有空间。

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

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