Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RTL support on ImageButton with autoMirror for src drawable

When creating an ImageButton with android:background="?android:attr/selectableItemBackground" and android:src="@drawable/ic_action_send", adding android:autoMirror="true" does not have any descernable affect. Is there any way to easily support Right-To-Left (RTL) image mirroring on ImageButtons?

like image 759
Sky Kelsey Avatar asked Mar 03 '16 06:03

Sky Kelsey


Video Answer


2 Answers

  1. Add rotationY to the ImageView :

    < ImageView ... android:rotationY="@integer/rtl_mirror_flip"

  2. Declare rtl_mirror_flip as 0 (for ltr), or 180 (for rtl ) :

    < integer name="rtl_mirror_flip">0< /integer> or < integer name="rtl_mirror_flip">180< /integer>

like image 25
Atara Avatar answered Oct 26 '22 04:10

Atara


Make an XML drawable and set android:autoMirrored="true". This value is ignored before API 19.

res/drawable/icon_auto_mirrored.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/icon"
        android:autoMirrored="true"/>

Now use android:src="@drawable/icon_auto_mirrored in your layout.

like image 150
StevenCVAL Avatar answered Oct 26 '22 06:10

StevenCVAL