问题描述
我正在尝试创建自定义形状以用作菜单抽屉的背景.我遇到的问题是我无法获得想要的形状.目前,我正在Adobe Illustrator中将形状创建为svg,然后转换将其转换为XML可绘制对象,但效果不理想.我如何获得可绘制矢量以根据其父级( match_parent
)和内容( wrap_content
)缩放?
menu_shape.xml
我注意到的一个问题是,此形状不能完全响应,因为它实际上被挤压以适合视口,因此其行为因屏幕尺寸而异.
<矢量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"><路径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>
当前结果:
所需结果:
所需的结果实质上是一个大的圆圈,该圆圈稍微向右偏移
尝试一下
<矢量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"><路径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>
I am attempting to create a custom shape to use as the background for my menu drawer. The issue i'm experiencing is that i can't get the shape i want. At the moment i am creating the shape as an svg in Adobe Illustrator and then converting that into an XML drawable but it isn't having the desired effect. How can i get the vector drawable to scale depending on its parent (match_parent
) and content (wrap_content
)?
menu_shape.xml
An issue i've picked up on this is that this shape isn't exactly responsive as it is essentially being squeezed to fit the viewport and thus behaves extremely different depending on the screen size.
<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>
Current result:
Desired result:
The desired result is essentially a massive circle that is offset to the right slightly
Try this
<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>
这篇关于Android自定义矢量缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!