Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用菜单项在ActionBarSherlock中居中显示标题?_Android_Android Layout_Actionbarsherlock - Fatal编程技术网

Android 如何使用菜单项在ActionBarSherlock中居中显示标题?

Android 如何使用菜单项在ActionBarSherlock中居中显示标题?,android,android-layout,actionbarsherlock,Android,Android Layout,Actionbarsherlock,为了在我的顶部栏中居中显示标题,我为ActionBarSherlock设置了自定义视图,如下所示: ab.setDisplayShowCustomEnabled(true); ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); ab.setCustomView(R.layout.topbar); 我的自定义视图: <?xml version="1.0" encoding="utf-8"?> <RelativeLayo

为了在我的顶部栏中居中显示标题,我为ActionBarSherlock设置了自定义视图,如下所示:

ab.setDisplayShowCustomEnabled(true);

ab.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
ab.setCustomView(R.layout.topbar);
我的自定义视图:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/textView"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:padding="5dp"
    android:background="#00ff00"
    >
    <ImageView 
        android:id="@+id/sideMenuButton"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerVertical="true"
        android:src="@drawable/icon_menu"
        />
    <ImageView 
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:src="@drawable/logo"
        />

</RelativeLayout>
项目:

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

    <item
        android:id="@+id/menu_share"
        android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
        android:icon="@drawable/icon_foo"
        android:showAsAction="always"
        android:title="@string/foo"
        android:visible="false"/>

//...
</menu>

//...
我怎样才能得到顶栏的整个布局?如果我说“中心”,它真的在所有可用宽度的中心?我没有可能重叠的问题,因为居中的徽标和菜单项是固定大小的图像

我也可以测量屏幕的宽度并动态设置左边距,但我希望有更好的解决方案


提前谢谢。

您为什么要这样做?您偏离了标准,因此不必要地混淆了用户-尤其是如果您坚持操作栏模式的其他部分,如操作栏项目(菜单项)。因为我的客户希望标题/徽标位于中间,而不是左侧。这就是设计的方式,iOS应用程序也有这样的功能——左边的按钮是侧菜单,中间是标题,右边是其他按钮。这就是我害怕的。iOS和Android是完全不同的系统。你应该教育你的客户,否则客户会得到糟糕的应用评分。好吧,我当然会告诉客户关于Android视觉/可用性的指导原则,但我仍然看不到为什么iOS标题可以居中,而Android不能(或不应该)的实际原因。是的,我想客户可能会同意。现在,我想我可以在自定义视图中添加右按钮并完全禁用菜单选项——但是如果用户真的希望左侧有徽标,这对于客户端来说应该足够了。
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/menu_share"
        android:actionProviderClass="com.actionbarsherlock.widget.ShareActionProvider"
        android:icon="@drawable/icon_foo"
        android:showAsAction="always"
        android:title="@string/foo"
        android:visible="false"/>

//...
</menu>