Android 矢量可绘制图像在ImageView中看起来缩小了

Android 矢量可绘制图像在ImageView中看起来缩小了,android,android-vectordrawable,Android,Android Vectordrawable,矢量可绘制图像在ImageView中看起来非常小。请查看Imageview周围的空间 这是我的前景矢量可绘制图像的xml文件,保存在可绘制文件夹中 <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="108dp" android:height="108dp" android:viewportWidth="9

矢量可绘制图像在ImageView中看起来非常小。请查看Imageview周围的空间

这是我的前景矢量可绘制图像的xml文件,保存在可绘制文件夹中

 <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="108dp"
            android:height="108dp"
            android:viewportWidth="91.83673"
            android:viewportHeight="91.83673">
        <group android:translateX="0.9183673"
                android:translateY="38.918365">
            <path
                android:pathData="M49.245,0l0,13.057l-3.88,0l0,-8.612l-4.026,8.731l-2.396,0l-3.872,-8.731l0,8.612l-2.806,0l0,-13.057l5.074,0l3.464,7.993l3.624,-7.993z"
                android:strokeColor="#00000000"
                android:fillType="evenOdd"
                android:fillColor="#FFFFFF"
                android:strokeWidth="1"/>
            <path
                android:pathData="M61.856,0l0,2.435l-6.074,0l0,2.922l5.297,0l0,2.196l-5.297,0l0,3.067l6.199,0l0,2.556l-10.189,0l0,-13.176z"
                android:strokeColor="#00000000"
                android:fillType="evenOdd"
                android:fillColor="#FFFFFF"
                android:strokeWidth="1"/>
            <path
                android:pathData="M76.415,0l0,13.176l-4.309,0l-4.836,-8.451l0,8.451l-2.741,0l0,-13.176l4.435,0l4.711,8.306l0,-8.306z"
                android:strokeColor="#00000000"
                android:fillType="evenOdd"
                android:fillColor="#FFFFFF"
                android:strokeWidth="1"/>
        </group>
    </vector>


这是xml代码和视图(宽度和高度作为包装内容制作)

代码:

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

    <ImageView
        android:layout_marginTop="50dp"
        android:id="@+id/imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/foreground" />

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

    <ImageView
        android:layout_marginTop="50dp"
        android:id="@+id/imageview"
        android:layout_width="@dimen/width"
        android:layout_height="@dimen/height"
        android:layout_centerHorizontal="true"
        android:src="@drawable/foreground" />

</RelativeLayout>


这是xml代码和视图(宽度和高度我从dimens.xml获取)

代码:

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

    <ImageView
        android:layout_marginTop="50dp"
        android:id="@+id/imageview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:src="@drawable/foreground" />

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

    <ImageView
        android:layout_marginTop="50dp"
        android:id="@+id/imageview"
        android:layout_width="@dimen/width"
        android:layout_height="@dimen/height"
        android:layout_centerHorizontal="true"
        android:src="@drawable/foreground" />

</RelativeLayout>


我假设您的VectorDrawable从SVG开始

你的问题是你的SVG已经被设计成一个小块的文本,在一个更大的方形画布中间。在转换为VectorDrawable后,过大的画布大小被保留。VectorDrawable中的
视口宽度
视口高度
属性描述文档区域。它们约为92x92,但您的文本大小仅为44x13

您需要确保:

  • 您可以根据文档的大小调整文本,或者
  • 保存之前,可以将文档大小调整为对象(文本)的大小
  • 如果您使用的是Inkscape,那么有一种简单的方法来实现选项2。保存并转换为矢量绘图之前,请从菜单中选择
    Edit->Resize Page to Selection

    其他编辑器也应该具有类似的功能。如果不是,那么您可以在转换之前通过Inkscape运行它