【问题标题】:Action bar (Sherlock) menu items cutting off built-in Spinner操作栏 (Sherlock) 菜单项切断内置微调器
【发布时间】:2013-09-02 05:53:04
【问题描述】:

我的操作栏菜单项正在切断操作栏 Spinner 的宽度,因此 Spinner 的文本被截断。我已将所有菜单项设置为使用“ifRoom”,但不幸的是它们将原始 Spinner 宽度解释为可用空间。

这是当我有三个菜单项时的截断(是的,我知道第三个图标看起来与第二个相同):

这是我注释掉第三个菜单项时得到的结果。最终,我想要看起来像这样的东西,但显示的是溢出图标而不是搜索图标:

我使用自定义适配器(从 BaseAdapter 扩展并实现 SpinnerAdapter)填充 Spinner。

这是我的菜单 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>

这是我的 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>

我尝试过的:

  1. 将 ab_dropdown 的 RelativeLayout 和 TextView 的 minWidth 设置为 570dp。无论是在 XML 中设置还是在自定义适配器的 getView 方法中设置都没有效果。
  2. 将 RelativeLayout 和 TextView 的 layout_width 硬编码为 570dp。同样,对 XML 或代码没有影响。
  3. 我会尝试以编程方式查找操作栏 Spinner 以设置其宽度,但是当我 tried to do this for a different reason 时,我找不到。

有什么想法吗?

【问题讨论】:

    标签: android android-layout android-actionbar actionbarsherlock android-spinner


    【解决方案1】:

    就个人而言,我会切换到导航抽屉并转储下拉列表导航。

    话虽如此,听起来您需要两个版本的菜单资源。将工具栏中的第三项默认设置为 never(始终处于溢出状态),并在较大的屏幕上设置为 ifRoom(例如,res/menu-sw600dp/)。

    您还可以尝试使用AutoScaleTextView 作为下拉列表导航标签。

    操作栏的导航部分被认为是最不重要的,这就是ifRoom 认为有空间的原因。

    【讨论】:

      猜你喜欢
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      相关资源
      最近更新 更多