Cómo alinear la imagen en la barra de herramientas en Android

Estoy utilizando la barra de herramientas en mi activity.I quiere alinear a la derecha la foto del perfil del usuario. He utilizado android: layout_alignParentRight = "true". Pero no funciona.

1. XML

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <!--Top Toolbar--> <android.support.v7.widget.Toolbar android:id="@+id/toolbar_top" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:background="#3f5e7e" android:elevation="6dp" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:popupTheme="@style/ThemeOverlay.AppCompat.Light" > <com.sevenhorse.View.CircularImageView android:id="@+id/profile" android:layout_width="40sp" android:layout_height="40sp" android:layout_alignParentRight="true" android:foregroundGravity="right" /> <!-- android:layout_centerVertical="true"--> </android.support.v7.widget.Toolbar> <android.support.design.widget.TabLayout android:id="@+id/tab_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/toolbar_top" android:background="#fbae38" android:elevation="6dp" android:minHeight="?attr/actionBarSize" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" app:tabGravity="fill" app:tabMode="fixed"/> <android.support.v4.view.ViewPager android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_above="@+id/reltv_footer" android:layout_below="@+id/tab_layout"></android.support.v4.view.ViewPager> <RelativeLayout android:id="@+id/reltv_footer" android:layout_width="match_parent" android:layout_height="50sp" android:layout_alignParentBottom="true" android:background="#2b4d72"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:padding="20sp" /> <ImageView android:id="@+id/img_Profile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="#2b4d72" android:padding="15sp" android:src="@drawable/more_option" /> <View android:id="@+id/img_view" android:layout_width="3sp" android:layout_height="fill_parent" android:layout_toLeftOf="@+id/img_Profile" android:background="#335980" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_toLeftOf="@+id/img_view" android:background="#2b4d72" android:gravity="left" android:orientation="horizontal"> <ImageView android:id="@+id/home" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="#203b58" android:padding="15sp" android:src="@drawable/home" /> <View android:layout_width="2sp" android:layout_height="fill_parent" android:layout_toLeftOf="@+id/img_Profile" android:background="#203b58" /> <ImageView android:id="@+id/friendrequest" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:padding="15sp" android:src="@drawable/friend_req" /> <View android:layout_width="2sp" android:layout_height="fill_parent" android:layout_toLeftOf="@+id/img_Profile" android:background="#203b58" /> <ImageView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:padding="15sp" android:src="@drawable/meg" /> <View android:layout_width="2sp" android:layout_height="fill_parent" android:layout_toLeftOf="@+id/img_Profile" android:background="#203b58" /> <ImageView android:id="@+id/notification" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:padding="15sp" android:src="@drawable/footer_notification" /> </LinearLayout> </RelativeLayout> <RelativeLayout android:id="@+id/reltv_Menu" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/reltv_footer" android:layout_alignParentRight="true" android:background="#ffffff" android:visibility="gone"> <ListView android:id="@+id/listviewmoroption" android:layout_width="200sp" android:layout_height="wrap_content" android:divider="#6d6d6d" android:dividerHeight="1sp"></ListView> </RelativeLayout> </RelativeLayout> <FrameLayout android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent" /> <LinearLayout android:id="@+id/left_drawer" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="right" android:background="@android:color/white" android:choiceMode="singleChoice" android:orientation="vertical"> <include layout="@layout/cust_rightnavigationdrawer" /> </LinearLayout> 

2.ScreenShot

Captura de pantalla

¿Cómo puedo alinear la imagen al extremo derecho de la barra de herramientas?

Solo puedes usar android:layout_alignParentRight="true" dentro de un RelativeLayout , y Toolbar es un ViewGroup simple. Para lograr la alineación, agregue un RelativeLayout dentro de la Toolbar y mueva ImageView dentro de ella:

 <android.support.v7.widget.Toolbar ... > <RelativeLayout ...> <com.sevenhorse.View.CircularImageView ... android:layout_alignParentRight="true" ... /> </RelativeLayout> </android.support.v7.widget.Toolbar> 

Trate de darle a android:layout_gravity="right"

 <com.sevenhorse.View.CircularImageView android:id="@+id/profile" android:layout_width="40sp" android:layout_height="40sp" android:foregroundGravity="right" android:layout_gravity="right" android:layout_alignParentRight="true" /> 

Adentro usted puede poner cualquier disposición como disposición linear, disposición del capítulo, él trabajará muy bien

  • Que el ancho de diseño debe ser coincidente
  • Estilo appcompat-v7 Fondo de menú de la barra de herramientas
  • Toolbar.inflateMenu parece no hacer nada
  • NullPointerException al configurar la barra de herramientas
  • Alinear texto en el centro de la barra de herramientas
  • Cambiar el menú de la barra de herramientas Color del elemento (acción no oculta)
  • Cómo personalizar la fuente de subtítulos de la barra de acción?
  • Cómo configurar la aplicación: layout_scrollFlags para la barra de herramientas mediante programación
  • Cómo centrar el menú de acciones en la barra de herramientas
  • Estilo de la barra de herramientas Android
  • ViewPager con la barra de herramientas y TabLayout tiene altura incorrecta
  • Añadir diseño personalizado a ActionBar / Toolbar sin márgenes
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.