The action bar will not be aligned correctly (RelativeLayout)

I am trying to create my action bar to have a textual representation at the dead center of the action bar, as well as the image in the far right corner of the action bar, but I just can not get the image to align to the right.

The image will move my text image to the left and leave a lot of space to the right of the image, no matter what different attributes change me.

Here is an example of a custom action_bar XML layout that is overpriced in my work.

[![ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" android:weightSum="3" > <ImageButton android:src="@drawable/users" android:background="?attr/actionBarItemBackground" android:layout_width="24dp" android:layout_height="24dp" android:scaleType="centerInside" android:id="@+id/item2" android:layout_alignParentRight="true" android:layout_alignParentTop="false"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="Location" android:id="@+id/textView2" android:layout_gravity="center_horizontal" android:textStyle="bold" android:textColor="#ffffff" android:layout_centerHorizontal="true" /> </RelativeLayout> 

Here is an example of what is happening

0
source share
1 answer

Instead of the action bar, you can use the toolbar.

 <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:minHeight="?attr/actionBarSize" android:background="#03a9f4" android:layout_width="match_parent" android:layout_height="56dp" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" > <TextView android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="48dp" android:gravity="center" android:textColor="#ffffff" android:textSize="14sp" android:text="@string/profile_setup" android:id="@+id/title"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/join" android:paddingRight="24dp" android:textColor="#ffffff" android:textSize="14sp" android:id="@+id/actionButton" /> </android.support.v7.widget.Toolbar> 
0
source

All Articles