简体   繁体   中英

Why is there a left space on the left of linear layout?

安卓工作室设计的形象

 <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content"> <androidx.appcompat.widget.Toolbar android:id="@+id/myToolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#019032" android:padding="20dp" android:gravity="center_horizontal"> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:layout_marginLeft="0dp" android:paddingLeft="0dp" android:src="@drawable/menu" /> <TextView android:layout_width="0dp" android:layout_height="match_parent" android:layout_gravity="center" android:textAlignment="center" android:layout_weight="1" android:textStyle="bold" android:textSize="18dp" android:text="Falesie in Italia" /> <ImageView android:layout_width="25dp" android:layout_height="25dp" android:src="@drawable/menu" /> </LinearLayout> </androidx.appcompat.widget.Toolbar> </androidx.constraintlayout.widget.ConstraintLayout>

I'm trying to add a Toolbar on my app and i have a little space on the left of linear layout.

This is the code of my main activity layout, i tried to change padding and margin of all the element but the situation doasn't change.

Does anyone know why?

Preview in my Android Studio The problem is with caches

Try

  • Copy the file content
  • Delete the file
  • File > Invalidate & Restart
  • Gradle sync
  • Create new file with different name
  • Check the preview
  • Run the app and check
  • Rename to original name

▲ this answer if it helps!

Could you try

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

it will be like this

<androidx.appcompat.widget.Toolbar
    android:id="@+id/myToolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:contentInsetLeft="0dp"
    app:contentInsetStart="0dp"
    android:padding="0dp">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM