Подтвердить что ты не робот

Необъяснимый пробел/отступы слева, между панелью инструментов и LinearLayout

У меня есть следующая структура в файле макета моего проекта студии Android, и я вижу необъяснимое левое дополнение между родительским элементом (панель инструментов) и его непосредственным дочерним элементом (LinearLayout).

Текст макета

<Toolbar
    android:layout_width="fill_parent"
    android:layout_height="600dp"
    android:id="@+id/toolbar"
    android:background="#313B45"
    android:weightSum="1">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" android:orientation="vertical">
        <ImageView
            android:id="@+id/headerimage"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="fitXY"
            android:layout_gravity="left|top"
            android:layout_weight="1"/>

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:text="New Text"
            android:id="@+id/textView"
            android:scaleType="fitXY"
            android:layout_gravity="left|top"
            android:layout_weight="1"/>

    </LinearLayout>
</Toolbar>

Как я могу удалить этот пробел и полностью ли выровнять LinearLayout с родительской панелью инструментов?

4b9b3361

Ответ 1

Добавьте эти строки в макет панели инструментов:  Для панели инструментов API <= 21:

    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"

Для API 21 >= панель инструментов:

    android:contentInsetLeft="0dp"
    android:contentInsetStart="0dp"

Левая вставка вызвана содержимым панели инструментовInsetStart, который по умолчанию равен 16dp.

Здесь полный код:

<android.support.v7.widget.Toolbar
android:layout_width="fill_parent"
android:layout_height="600dp"
android:id="@+id/toolbar"
android:background="#313B45"
android:weightSum="1"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/headerimage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scaleType="fitXY"
        android:layout_gravity="left|top"
        android:layout_weight="1" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="New Text"
        android:id="@+id/textView"
        android:scaleType="fitXY"
        android:layout_gravity="left|top"
        android:layout_weight="1" />

</LinearLayout>

Ответ 2

Вышеупомянутый ответ помог решить только часть, добавить эти строки, и она должна работать нормально

android.support.v7.widget.Toolbar
        xmlns:app="schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/primaryColor"
        android:contentInsetLeft="0dp"
        android:contentInsetStart="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetStart="0dp"
        android:contentInsetRight="0dp"
        android:contentInsetEnd="0dp"
        app:contentInsetRight="0dp"
        app:contentInsetEnd="0dp" />

обратите внимание, что андроид: contentInsetLeft и приложение: contentInsetLeft - это две отдельные вещи и оба из них необходимы