嗨,我正在尝试在我的Android应用程序中使用vector drawable。
这是相同的xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1024dp"
android:height="1024dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M 0,0 L 50,0 L 50,50 z"
android:strokeColor="#000000" />
</vector>
如果我添加android:strokeWidth =“ 10”,则外观如下
所有行的笔画宽度不一致(相同宽度),最左边的点似乎没有被截断
有没有办法使所有绘制的3条线一致(相同宽度)而不是不规则?
想象将可绘制对象作为坐标系统,将点p(0,0)放在左上角。您的x轴从左上角到右上角,您的y轴从左上角到左下角。
创建路径时,它会在坐标系中从一个点延伸到另一个点。抚摸此路径时,绘制的线strokeWidth
默认为1。但是,当您将宽度设置为10时,该线在坐标系中要粗得多,但是如果您的路径已经在y = 0处,那么该“厚度”应该去哪里?可绘制对象不会显示任何负坐标。这就是为什么您的可绘制对象被切断。
解决方案:将strokeWidth
小于等于strokeWidth
+的坐标添加到strokeWidth
大于viewportWidth-strokeWidth
和/或从坐标中减去的坐标和/或viewportHeight-strokeWidth
+为位于视口边界处的边给定间距(在此示例中为3很好)
因此,您的代码应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1024dp"
android:height="1024dp"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:pathData="M 13,13 L 50,13 L 50,50 z"
android:strokeColor="#000000"
android:strokeWidth="10"/>
</vector>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句