29

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.

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

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:

<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>

And when I add:

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

to rotationGroup it is tilted to the right.

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

Banana
  • 2,435
  • 7
  • 34
  • 60

1 Answers1

78

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

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>
Lewis McGeary
  • 7,692
  • 2
  • 40
  • 46
  • Information: `android:pivotX="Z"` the static Z has to be half of the value of your `android:viewportWidth` – Harpreet Dec 30 '20 at 09:41