ImageButton上的RTL支持,带有用于src drawable的autoMirror

Sky*_*sey 6 android right-to-left

使用android:background="?android:attr/selectableItemBackground"和创建ImageButton时android:src="@drawable/ic_action_send",添加android:autoMirror="true"没有任何可辨别的影响.有没有办法轻松支持从右到左(RTL)图像镜像ImageButtons

小智 14

创建一个XML drawable并设置android:autoMirrored="true".在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"/>
Run Code Online (Sandbox Code Playgroud)

现在使用android:src="@drawable/icon_auto_mirrored你的布局.


Ata*_*ara 7

  1. 添加rotationYImageView

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

  2. 声明rtl_mirror_flip为 0(对于 ltr)或 180(对于 rtl):

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