Android mirror vector drawable

安稳与你 提交于 2020-08-06 11:39:29

问题


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

回答1:


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

.




回答2:


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

and your are done. :)




回答3:


Set android:autoMirrored="true" in your XML vector file,




回答4:


Here is the share image vectore xml file share.xml :

<vector android:height="24dp" android:tint="#FFFFFF"
    android:viewportHeight="24.0" android:viewportWidth="24.0"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#FF000000" android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z"/>
</vector>

Here is the image in xml layout file :

<ImageView
      android:layout_width="32dp"
      android:layout_height="32dp"
      android:src="@drawable/share"
      android:scaleX="-1"
      android:scaleType="fitCenter"/>

This line is used to mirror a vector image :

   android:scaleX="-1"


来源:https://stackoverflow.com/questions/36329687/android-mirror-vector-drawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!