Наложение ImageView на панель инструментов

У меня есть этот код для моей пользовательской панели инструментов:

 <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:src="@drawable/new_logo"
                android:adjustViewBounds="true"
                android:padding="5dp"
                android:id="@+id/app_logo" />

        </android.support.v7.widget.Toolbar>

Теперь это выглядит так:
https://stackru.com/images/49767636b989b51a7cff883857a1a3aafe3649c3.png

Что мне нужно сделать, это:
https://stackru.com/images/be8b0eb5eea9af2a9fc5e4ca4ea35c8776533eb4.png

Как я это реализую?

2 ответа

Решение

Попробуй это:

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/login_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="90dp"
            android:src="@mipmap/ic_launcher"
            android:layout_centerHorizontal="true"
            android:id="@+id/app_logo" />

    </RelativeLayout>

Вы должны принять RelativeLayout в качестве корня следующим образом:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/login_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/colorPrimary">

    </android.support.v7.widget.Toolbar>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_stripe"
        android:layout_centerHorizontal="true"
        android:adjustViewBounds="true"
        android:padding="5dp"
        android:id="@+id/app_logo" />

</RelativeLayout>
Другие вопросы по тегам