ActionBar mit benutzerdefiniertem Layout mit benutzerdefiniertem Menüelement

Ich möchte eine benutzerdefinierte Aktionsleiste per Put erstellenImageView in der Mitte und haben ein weiteres Symbol mit einigen Informationen auf der rechten Seite der Aktionsleiste wie folgt:

Ich kann das Imageview schon in der Mitte machen, aber das Problem ist

wenn ich das Layout aufblaseonCreateOptionMenu() und setzenshowAsAction="always" Die Ansicht auf der rechten Seite nimmt den gesamten Raum der Aktionsleiste so ein

aber wenn ich es auf setze"never" Das mittlere Bild wird angezeigt, aber der Menüpunkt wird ausgeblendet

Hier ist mein Code:

private void setActionBar(){
        actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);

        LayoutInflater linflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View view = linflater.inflate(R.layout.actionbar_layout, null);
        ActionBar.LayoutParams lp = new ActionBar.LayoutParams(
                ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT);
        lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
        view.setLayoutParams(lp);
        actionBar.setCustomView(view);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater menuInflater = getMenuInflater();
        menuInflater.inflate(R.menu.actionbar_right_icon, menu);
        MenuItem menuItem = menu.findItem(R.id.user_info);

        View rightIcon = menuItem.getActionView();
        RelativeLayout rightIconLayout = (RelativeLayout) rightIcon.findViewById(R.id.actionbar_right_icon);
        TextView user = (TextView) rightIconLayout.findViewById(R.id.actionbar_user);
        TextView id = (TextView) rightIconLayout.findViewById(R.id.actionbar_id);

        user.setText("User:test");
        id.setText("ID:xxxxx");

        return true;
    }

menu / actionbar_right_icon

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    >
    <item 
        android:id="@+id/user_info"
        android:actionLayout="@layout/actionbar_right_icon_layout"
        android:icon="@drawable/user_icon"
        android:showAsAction="always"

        />
</menu>

Wie kann ich das beheben?

danke im Voraus

Antworten auf die Frage(1)

Ihre Antwort auf die Frage