代码之家  ›  专栏  ›  技术社区  ›  greywolf82

具有矢量可绘制大小的ImageView

  •  4
  • greywolf82  · 技术社区  · 8 年前

    我使用的是矢量绘图,我希望我的图像视图背景为40dp,图像为24dp。 我现在有了这个布局:

    <ImageView
                android:id="@+id/image"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@drawable/circle"
                android:src="@drawable/ic_image"
                android:tint="@android:color/white"
                tools:ignore="ContentDescription"/>
    

    <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="24dp"
            android:height="24dp"
            android:viewportWidth="24.0"
            android:viewportHeight="24.0">
    

    可绘制的圆为:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
           android:shape="oval">
        <solid
            android:color="@color/colorAccent"/>
        <size
            android:width="40dp"
            android:height="40dp"/>
    </shape>
    

    如何修复布局?我需要将矢量转换为png吗?

    1 回复  |  直到 8 年前
        1
  •  6
  •   greywolf82    8 年前

    我用解决了这个问题 android:scaleType 有价值 center .