【问题标题】:Drawables by country AndroidDrawables 按国家/地区 Android
【发布时间】:2013-06-18 15:28:43
【问题描述】:

我正在将我的应用程序翻译成几种语言,但现在我遇到了一个问题!我有几张带有文字的图片,有没有办法使用国家代码提供可绘制资源?如果我使用国家代码将drawable添加到我的应用程序中会增加应用程序的大小吗?我不希望仅仅因为这些图像而将现在 1MB 的应用程序变为 4 或 5。

谢谢!

【问题讨论】:

    标签: android resources translation drawable


    【解决方案1】:

    等于你用 res 目录设置不同的语言 values-es values-fr values ... 您可以使用目录为每个位置设置不同的可绘制对象:

    drawable-es drawable-fr ... http://developer.android.com/training/basics/supporting-devices/languages.html

    请记住,目录的额外信息具有特殊重要性,您应该放在正确的位置http://developer.android.com/guide/topics/resources/providing-resources.html 比如drawable-es-hdpi

    您的 apk 大小的问题我想您不需要为所有国家/地区设置不同的所有图像,不是吗?一般只需要配置几张图片

    【讨论】:

      【解决方案2】:

      是的,可以按国家/地区提供资源。查看此答案以获取有关如何操作的详细信息:Localization and drawables

      它肯定会增加您的应用程序的大小。就像软件开发中的其他一切一样,它是性能(或图像质量)和资源(在这种情况下是 apk 的大小)之间的折衷。为避免成倍增加应用的大小,您可以尝试按地区而不是国家/地区提供资源,或者只提供 hdpi 版本。

      【讨论】:

        【解决方案3】:

        如果您不想使用不同的可绘制对象增加 apk 的大小,您可以编写自定义 ImageView 并使用字符串(将被翻译)在其上设置文本或将 textView 放在顶部ImageView 将它们设置在这样的相对布局中:

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"    
          android:gravity="center"
          android:orientation="vertical"
         >
        
        <ImageView
            android:id="@+id/yImage"
            android:layout_width="fill_parent"
            android:layout_height="25dp"/>  
        
        <TextView
            android:id="@+id/yTextView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/yImage"
            android:layout_alignLeft="@+id/yImage"
            android:layout_alignRight="@+id/yImage"
            android:layout_alignTop="@+id/yImage"
            android:background="@color/transparent"
            android:lines="2"
            android:textColor="@color/Black"
            android:textSize="14sp"
            android:textStyle="bold" />
        </RelativeLayout>
        

        使用框架布局也很容易。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-20
          • 2013-07-13
          • 2015-11-27
          相关资源
          最近更新 更多