Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android自定义向量缩放_Android_Android Drawable_Android Shape - Fatal编程技术网

Android自定义向量缩放

Android自定义向量缩放,android,android-drawable,android-shape,Android,Android Drawable,Android Shape,我正在尝试创建一个自定义形状,用作菜单抽屉的背景。我遇到的问题是,我无法得到我想要的形状。目前,我正在AdobeIllustrator中创建一个svg形状,然后将其转换为XML可绘制图形,但没有达到预期效果。如何根据其父项(match\u parent)和内容(wrap\u content)使向量可绘制以缩放 菜单\u shape.xml 我注意到的一个问题是,这个形状没有完全响应,因为它基本上是被挤压以适应视口的,因此根据屏幕大小的不同,它的行为非常不同 <vector xmlns:an

我正在尝试创建一个自定义形状,用作菜单抽屉的背景。我遇到的问题是,我无法得到我想要的形状。目前,我正在AdobeIllustrator中创建一个svg形状,然后将其转换为XML可绘制图形,但没有达到预期效果。如何根据其父项(
match\u parent
)和内容(
wrap\u content
)使向量可绘制以缩放

菜单\u shape.xml
我注意到的一个问题是,这个形状没有完全响应,因为它基本上是被挤压以适应视口的,因此根据屏幕大小的不同,它的行为非常不同

<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
    android:viewportWidth="597.28"
    android:viewportHeight="542.16"
    android:width="597.28dp"
    android:height="542.16dp">
    <path
        android:pathData="M0.5 303.39V0.5H596.78V370.39S310.5 797.13 0.5 303.39Z"
        android:fillColor="#A92324"
        android:strokeColor="#231F20"
        android:strokeWidth="1"
        android:strokeMiterLimit="10" />
</vector>

当前结果:

所需结果:
所需的结果基本上是一个巨大的圆圈,略微向右偏移
试试这个

<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
        android:viewportWidth="597.28"
        android:viewportHeight="542.16"
        android:width="597.28dp"
        android:height="542.16dp">
  <path
          android:pathData="M0.5 302.39V0.5H596.7V374.39S310.5 501.13 0.5 303.39Z"
          android:fillColor="#A92324"
          android:strokeColor="#231F20"
          android:strokeWidth="1"
          android:strokeMiterLimit="10" />
</vector>

试试形状xml代码



@Sha-1您有形状的SVG吗?这给了我想要的形状,但是我如何根据布局中的内容来增加形状的高度?使用vector drawable,android:width和android:height仅对API<21或您的图像使用wrap_内容时有效。因此,您可以在布局xml代码中设置witdh和heigh,并且可以缩放矢量。我已经创建了一个相对布局,以可绘制为背景,使用
layout\u width:match\u parent
layout\u height:wrap\u content
。但是,形状并没有根据其内容进行调整,就好像形状的宽度和高度是永久设置的(它们似乎在您提供的xml中)。相对长度随高度增加而增加,但可绘制的背景不增加
<?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="rectangle">

                <padding android:left="-100dp"
                    android:top="-100dp"
                    android:right="-100dp"/>
            </shape>
        </item>
        <item>
            <shape xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="oval">
                <solid
                    android:color="#712EF1" />
            </shape>
        </item>
    </layer-list>