Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android mirror vector drawable

I use a material icon (ic_play_arrow_black_24dp), imported it with the vector studio.

Now I want the arrow to point in the other direction as well, without creating a second vector. Is this possible in xml and how?

I use the drawable in two Floating Action Button, one for next the other for previous.

Edit here is the fab button's XML. I tried already rotation and scale, but it didn´t work

<android.support.design.widget.FloatingActionButton
    android:id="@+id/previous"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="start|bottom"
    android:layout_marginBottom="0dp"
    android:layout_marginEnd="80dp"
    android:layout_marginStart="0dp"
    android:layout_marginTop="0dp"
    android:src="@drawable/next_prev_24dp"
    app:layout_anchor="@id/next"
    app:layout_anchorGravity="left" />
like image 995
reebow Avatar asked Mar 31 '16 09:03

reebow


People also ask

How do you make animated vector drawable?

Use AnimatedVectorDrawable You normally define animated vector drawables in three XML files: A vector drawable with the <vector> element in res/drawable/ An animated vector drawable with the <animated-vector> element in res/drawable/ One or more object animators with the <objectAnimator> element in res/animator/

What is FillType Evenodd?

Enum values. Path.FillType. EVEN_ODD. Specifies that "inside" is computed by an odd number of edge crossings.

What is use of vector drawable in android?

The major advantage of using a vector drawable is image scalability. It can be scaled without loss of display quality, which means the same file is resized for different screen densities without loss of image quality. This results in smaller APK files and less developer maintenance.

What is viewportWidth?

android:viewportWidth. Used to define the width of the viewport space. Viewport is basically the virtual canvas where the paths are drawn on. android:viewportHeight. Used to define the height of the viewport space.


2 Answers

For those who Use ImageView or TextView or EditText Scale works perfectly. Use

android:scaleX="-1" //To flip horizontally or
android:scaleY="-1" //To flip vertically

OR Try

android:rotationX="180" // for horizontal
android:rotationY="180" // for vertical

OR Simply rotation="180" for vertical

android:rotation="180" // for vertical

Edit: Additional
If you want to flip/mirror icons/drawable when changing language RTL/LTR ("Right To Left"/"Left To Right"), there is a nice way of doing so in android vector drawable just check the ckeckbox Enable auto mirroring for RTL layout.

=> Right Click on drawable folder => New => Vector Asset => Select drawable => check the Checkbox

.

like image 68
Inzimam Tariq IT Avatar answered Sep 25 '22 13:09

Inzimam Tariq IT


I am using AndroidStudio 3.0.1 in Windows 10.

well, there is no need to create another vector image, you can do it with one single vector image just make sure you do the following step while importing the vector image

So, do usual step to create vector_drawable,

in case some one don't know,

than here it is..

1.) Right Click on your package of your app

2.) Than navigate to New => Vector Asset

3.) Than choose your desired icon, in @reebov case it will be ic_arrow_back_black_24dp

4.) You will find Checkbox with the Option Enable auto mirroring for RTL layout.

EDIT

You can also Set android:autoMirrored="true" in your XML vector file

see below image for more info

see image for more info

and your are done. :)

like image 31
Ravi Vaniya Avatar answered Sep 22 '22 13:09

Ravi Vaniya