在矢量可绘制中翻转可绘制图像 [英] Fliping Drawable Image in Vector Drawable

查看:114
本文介绍了在矢量可绘制中翻转可绘制图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在此处找到了可绘制矢量的资源.我想做的就是翻转它,使 X 在另一侧.

I have found this vector drawable resource here. What I would like to do is flip it so the X is on the other side.

我设法在布局中执行此操作,例如在示例中通过添加: android:scaleX =-1" 到我的ImageView,它可以正常工作.

I managed to do this in the layout, like in this example by adding: android:scaleX="-1" to my ImageView and it works.

现在,我想直接在Vector Drawable中对其进行更改,但是当我尝试下面的代码时,它是不可见的.

Now I would like to change it directly in the Vector Drawable, but when I try the code below it is invisible.

account_remove.xml:

account_remove.xml:

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

    <group
        android:name="rotationGroup"
        android:scaleX="-1" >

        <path
            android:fillColor="#FFFFFF"
            android:pathData="M15,14C17.67,14 23,15.33 23,18V20H7V18C7,15.33 12.33,14 15,14M15,12A4,4 0 0,1 11,8A4,4 0 0,1 15,4A4,4 0 0,1 19,8A4,4 0 0,1 15,12M5,9.59L7.12,7.46L8.54,8.88L6.41,11L8.54,13.12L7.12,14.54L5,12.41L2.88,14.54L1.46,13.12L3.59,11L1.46,8.88L2.88,7.46L5,9.59Z" />
    </group>
</vector>

当我添加时:

android:pivotX="10.0"
android:pivotY="10.0"

rotationGroup ,它向右倾斜.

我应该为我的 rotationGroup 添加哪些值以使其正常工作?

What values should I add to my rotationGroup to make it work correctly?

推荐答案

您几乎都在这样做,只是用了错误的枢轴点.

You were almost doing it, just with the wrong pivot point.

它需要围绕图像的中心翻转,因此在视口中,整个宽度为24,因此枢轴点必须在12.

It needs to flip around the centre of the image, so looking at the viewport the full width is 24, so the pivot point needs to be at 12.

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

    <group
        android:name="rotationGroup"
        android:pivotX="12"
        android:scaleX="-1" >

        <path
            android:fillColor="#FFFFFF"
            android:pathData="M15,14C17.67,14 23,15.33 23,18V20H7V18C7,15.33 12.33,14 15,14M15,12A4,4 0 0,1 11,8A4,4 0 0,1 15,4A4,4 0 0,1 19,8A4,4 0 0,1 15,12M5,9.59L7.12,7.46L8.54,8.88L6.41,11L8.54,13.12L7.12,14.54L5,12.41L2.88,14.54L1.46,13.12L3.59,11L1.46,8.88L2.88,7.46L5,9.59Z" />
    </group>
</vector>

这篇关于在矢量可绘制中翻转可绘制图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆