保持drawable小于imageview

Keep the drawable smaller than the imageview

我有一个矢量可绘制图像,它的大小是 24dp。我想在更大的 Imageview 中显示图像,但将可绘制对象保持在中心 24dp 大小。 以下使可绘制对象变大:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:src="@drawable/the_image_drawable"
        />

</LinearLayout>

我做错了什么?

ImageView 有一些棘手的参数:ScaleType. by default it is set to FIT_CENTER, so in fact Matrix.ScaleToFit.CENTER。来自文档:

Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst. At least one axis (X or Y) will fit exactly. The result is centered inside dst.

尝试将此 attr 交换为 CENTERCENTER_INSIDE,这些根本不使用缩放

<ImageView
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:src="@drawable/the_image_drawable"
    android:scaleType="center"/>