Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.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
添加OnCreateOptions菜单的自定义操作栏不居中标题Android?_Android_Android Layout - Fatal编程技术网

添加OnCreateOptions菜单的自定义操作栏不居中标题Android?

添加OnCreateOptions菜单的自定义操作栏不居中标题Android?,android,android-layout,Android,Android Layout,我已经创建了自定义操作栏,它有ImageView(在左边)和TextView(在右边)。但是,我在活动中有不同的片段,其中有几个片段需要在CreateOptions菜单中显示。若有onCreateOptions,则操作栏的菜单标题会被推到左侧,并且不会显示在中间 它看起来像以下操作栏+OnCreateOptions菜单: 如您所见,当添加onCreateOptions菜单时,下载文本有点向左倾斜 如果没有onCreateOptions,则文本居中,如下所示: 这是我的自定义操作条形码: &l

我已经创建了自定义操作栏,它有ImageView(在左边)和TextView(在右边)。但是,我在活动中有不同的片段,其中有几个片段需要在CreateOptions菜单中显示。若有onCreateOptions,则操作栏的菜单标题会被推到左侧,并且不会显示在中间

它看起来像以下操作栏+OnCreateOptions菜单:

如您所见,当添加onCreateOptions菜单时,下载文本有点向左倾斜

如果没有onCreateOptions,则文本居中,如下所示:

这是我的自定义操作条形码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/menubutton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:paddingLeft="5dp"
        android:src="@drawable/navigation_icon" />

    <TextView
        android:id="@+id/titleofscreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:textColor="#22c064"
        android:textSize="22sp"
        android:textStyle="bold" />

</RelativeLayout>

我不想在自定义操作栏中将CreateOptions菜单设置为imageView,因为这会使事情变得复杂。

试试这个

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/menubutton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:paddingLeft="5dp"
            android:src="@drawable/navigation_icon" />

        <TextView
            android:id="@+id/titleofscreen"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@+id/menubutton"
            android:gravity="center"
            android:textColor="#22c064"
            android:textSize="22sp"
            android:textStyle="bold" />

    </RelativeLayout>


@vo12这次尝试与右图对齐。希望它能解决您的问题。答案编辑您看过API 21中的
工具栏了吗?我注意到你有五个问题,包括这一个,你要求优先处理其他问题。请不要这样做-请记住,这里的读者主要是志愿者,他们会在空闲时回答他们感兴趣的问题。谢谢