在工具栏中对齐 imageview 旁边的投射菜单项

Align cast menu item next to imageview in Toolbar

我想将投射按钮菜单项对齐到工具栏中图像视图的左侧,但我不知道如何。

我在 menu_main.xml 中添加了投射按钮

    <item
    android:id="@+id/media_route_menu_item"
    android:title="@string/media_route_menu_title"
    app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
    app:showAsAction="always" />

ImageView 位于工具栏的布局 xml 中。

<ImageView
android:id="@+id/profile_picture"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:layout_marginRight="16dp"
android:adjustViewBounds="true"
android:clickable="true"
android:contentDescription="@string/profile"
android:scaleType="centerCrop"
android:src="@drawable/profilepicture" />

如何将投射按钮对齐到 ImageView 的左侧?现在添加在ImageView右侧工具栏的末尾

我猜不可能,因为官方文件说 Toolbar

One or more custom views. The application may add arbitrary child views to the Toolbar. They will appear at this position within the layout.

An action menu. The menu of actions will pin to the end of the Toolbar offering a few frequent, important or typical actions along with an optional overflow menu for additional actions.

替代解决方案是:
在 menu.xml 中,对菜单项使用自定义布局 android:actionLayout(即 ImageView)。