【发布时间】:2022-01-01 11:36:18
【问题描述】:
<?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>
我正在尝试在我的应用上添加一个工具栏,我在线性布局的左侧有一点空间。
这是我的主要活动布局的代码,我尝试更改所有元素的填充和边距,但情况并没有改变。
有谁知道为什么?
【问题讨论】:
-
预览可能有问题,转到文件 > 无效并重新启动
-
感谢您的回复,我尝试了您的建议,但我还有空间。
-
很奇怪!一切似乎都正确
-
您的代码没有问题。运行它,它应该可以正常工作。布局检查器不时会做这样的事情。我只是关闭检查器并再次打开它
-
不幸的是,问题不仅存在于预览中,还存在于应用程序中。
标签: android constraints android-linearlayout android-toolbar android-constraintlayout