【问题标题】:How can i apply the proper image to the ImageView based on the application Locale?如何根据应用程序区域设置将正确的图像应用于 ImageView?
【发布时间】:2017-09-24 08:07:51
【问题描述】:

有什么方法可以为 ImageView 提供不同语言的不同图像?

假设我有这两张图片,第一张是从右到左的语言,第二张是从左到右的语言,如何根据我的应用程序区域设置将正确的图像应用到 ImageView?

  <ImageView
    android:id="@+id/message_icon"
    android:layout_width="@dimen/message_text_icon"
    android:layout_height="@dimen/message_text_icon"
    android:src="@drawable/sent_message_icon"
    android:padding="@dimen/padding_small"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true"></ImageView>

【问题讨论】:

标签: android android-imageview android-drawable


【解决方案1】:

将普通图像放在drawable-* 文件夹中 rtl 图像在drawable-ldrtl-* 文件夹中。

如果你想使用单张图片:

&lt;integer name="angle_rtl_180"&gt;0&lt;/integer&gt; 放入values/integers

&lt;integer name="angle_rtl_180"&gt;180&lt;/integer&gt; in values-ldrtl/integers

然后在imageView中使用rotationY属性为:

android:rotationY="@integer/angle_rtl_180"

【讨论】:

  • 是*我的语言环境吗?像drawable-ldrtl-fa?
  • 屏幕密度,如drawable-hdpi、drawable-xhdpi等
【解决方案2】:

不需要像您提到的场景那样创建不同的图像,因为这会增加 apk 的大小。您需要检查语言是否有变化,是否有旋转视图的方法。您只需围绕 x 和 y 轴旋转通过所需的旋转角度即可完成。你可以使用下面的代码来旋转

imageView.setRotation(angle);

angle 是要旋转的值 希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    相关资源
    最近更新 更多