I have created a custom toolbar with an image as a centered title and another aligned to the right. I have used a relative layout to house the imageviews. But the relative layout doesn't seem to cover the entire length of the toolbar despite its width being set to match_parent. The code is as follows:
activity_main.xml
<android.support.v7.widget.Toolbar
android:id="@+id/app_bar"
android:minHeight="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="?attr/colorPrimary">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="150dp"
android:layout_height="30dp"
android:src="@drawable/title"
android:id="@+id/title_image"
android:layout_centerInParent="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/oie_transparent"
android:layout_alignParentRight="true"
android:id="@+id/cart_icon"
android:layout_toRightOf="@id/title_image"
android:layout_marginTop="2dp"
android:layout_marginLeft="30dp"
android:layout_marginBottom="2dp"/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); // an example activity_main.xml is provided below
Toolbar tb = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(tb);
}