How to right Align the image on the Toolbar in Android
Try to give 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"
/>
Add RelativeLayout in Toolbar and then use android:layout_alignParentRight="true"
with CircularImageView
<!--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"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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"-->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
You can only use android:layout_alignParentRight="true"
inside a RelativeLayout
, and Toolbar
is a simple ViewGroup
. To achieve the alignment, add a RelativeLayout
inside the Toolbar
and move the ImageView
inside it:
<android.support.v7.widget.Toolbar
...
>
<RelativeLayout
...>
<com.sevenhorse.View.CircularImageView
...
android:layout_alignParentRight="true"
...
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>