Android ConstraintLayout 未居中视图

Android ConstraintLayout not centering view

我正在尝试将 ImageView 置于 ConstraintLayout 的中心,如下所示。

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:src="@android:drawable/presence_busy"
        android:layout_width="70dp"
        android:layout_height="70dp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

这是结果:

我目前正在使用 androidx.constraintlayout:constraintlayout:2.0.4

如何使 ImageView 居中?

如果您在渲染设计时看到这是一个问题,因为代码是正确的。确保您在 build.gradle 中实现了 ConstraintLayout。如果这种情况仍然发生,请尝试重新启动您的 Android Studio。转到 文件 > 使缓存无效/重新启动...

从 Android Studio 4.0.2 更新到 4.1.1 解决了这个问题。在 Android Studio 4.0.2.

上使缓存失效并重新启动未能解决问题