为什么 CustomView 会忽略 app:srcCompat 属性中定义的可绘制对象?

Why does CustomView ignore drawables that are defined in app:srcCompat attribute?

当通过子类化 ImageView 创建自定义视图时,自定义视图是否仍能够呈现通过 app:srcCompat="@drawable/some_drawing" 属性定义的可绘制资源?我不明白为什么它不会,但它对我不起作用。构建和执行是干净的,但图纸没有出现。可能有名字 space 问题?

res/layout/activity_main.xml:

<?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="match_parent"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="104dp"
        tools:layout_editor_absoluteY="251dp">

        <com.example.testapp.CustomView
            android:id="@+id/customView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:srcCompat="@drawable/some_drawing" />

java/com.示例.testapp/CustomView:

class CustomView : ImageView {
    constructor(context: Context) :
            super(context) {
    }

    constructor(context: Context, attributeSet: AttributeSet) :
            super(context, attributeSet) {
    }

    constructor(context: Context, attributeSet: AttributeSet, defStyle: Int) :
            super(context, attributeSet, defStyle) {
    }
}

您需要扩展 AppCompatImageView 而不是 ImageView