簡體   English   中英

包含的工具欄有奇怪的邊距(Android 約束布局)

[英]Included toolbar has weird margin (Android Constraint layout)

我嘗試用約束布局重建我的工具欄,但有些事情我無法自己解決。

我在另一個布局中使用包含的工具欄,一切看起來都不錯,但是包含的工具欄有奇怪的左邊距。 我檢查了所有邊距和填充,但仍然......

圖片:

包含工具欄的奇怪邊距

在此處輸入圖像描述

如您所見,父 Toolbar 和包含的 new_toolbar 之間有一個空格

活動.xml:

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="56dp"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize"
    android:padding="0dp"
    app:titleTextColor="@android:color/white">

    <include
        android:id="@+id/actionBar"
        layout="@layout/new_toolbar" />

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

<ListView
    android:id="@+id/listAccount"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="56dp"/>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_navigation"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:layout_alignParentBottom="true"
    app:layout_anchor="@id/listAccount"
    app:layout_anchorGravity="bottom"

    app:itemBackground="@color/white"
    app:itemIconTint="@drawable/selector_bottom_navigation"
    app:itemTextColor="@drawable/selector_bottom_navigation"
    app:menu="@menu/bottom_navigation"/>
</android.support.design.widget.CoordinatorLayout>

new_toolbar.xml

<ImageButton
    android:id="@+id/mainIcon"

    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="16dp"
    app:layout_constraintLeft_toLeftOf="parent"
    android:layout_marginLeft="16dp"

    android:layout_height="24dp"
    android:layout_width="24dp"

    android:background="@null"
    android:tint="@color/white"
    app:srcCompat="@drawable/ic_menu_black_24dp" />

<TextView
    android:id="@+id/title"

    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="14dp"
    app:layout_constraintLeft_toRightOf="@+id/mainIcon"
    android:layout_marginLeft="32dp"

    android:layout_height="24dp"
    android:layout_width="wrap_content"

    android:fontFamily=" Roboto Semibold"
    android:text="Title"
    android:textColor="@color/white"
    android:textSize="20sp" />

<ImageButton
    android:id="@+id/rightIcon1"

    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="16dp"
    app:layout_constraintRight_toRightOf="parent"
    android:layout_marginRight="16dp"

    android:layout_height="24dp"
    android:layout_width="24dp"

    android:background="@null"
    android:tint="@color/white"
    app:srcCompat="@drawable/ic_add_black_24dp" />

<ImageButton
    android:id="@+id/rightIcon2"

    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginTop="16dp"
    app:layout_constraintRight_toLeftOf="@+id/rightIcon1"
    android:layout_marginRight="8dp"

    android:layout_height="24dp"
    android:layout_width="24dp"

    android:background="@null"
    android:tint="@color/white"
    app:srcCompat="@drawable/ic_account_circle_black_24dp" />
</android.support.constraint.ConstraintLayout>

在您的工具欄小部件中,使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM