简体   繁体   English

Android SVG 和视口

[英]Android SVG and Viewport

I have an SVG and it always seems the w/h (100/100) is always the same as the viewport sizes.我有一个 SVG,w/h (100/100) 似乎总是与视口大小相同。 If I change the viewport to be less it always starts at 0,0 and goes to 50,50如果我将视口更改得更小,它总是从 0,0 开始到 50,50

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

尺寸 100x100,视口 100x100

here is half the sizes and you get 1/4 the image, the top left.这是一半的尺寸,你得到 1/4 的图像,左上角。

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

尺寸 100x100,视口 50x50

What if I wanted to have the viewport take it from the middle and cut off the padding?如果我想让视口从中间取出它并切断填充怎么办? Like this.像这样。 How would I do this.我该怎么做。

我想要的居中视口

There are a couple of solutions:有几个解决方案:

The simplest is probably to load the SVG into a vector editor and move the shapes up into the corner;最简单的可能是将 SVG 加载到矢量编辑器中并将形状向上移动到角落; resize the document;调整文档大小; then save out the new SVG然后存出新的 SVG

Or you could manually add android:translateX and android:translateY attribute to the elements you want to move.或者您可以手动将android:translateXandroid:translateY属性添加到要移动的元素。 I can't tell you which elements you need to modify (or by how much) because you haven't posted the whole file.我无法告诉您需要修改哪些元素(或修改多少),因为您还没有发布整个文件。 You'll also need to update the android:viewportWidth and android:viewportHeight accordingly.您还需要相应地更新android:viewportWidthandroid:viewportHeight

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM