zoukankan      html  css  js  c++  java
  • Android 资源的国际化

    但是在实际应用开发中,通常横屏(land)与竖屏(port)布局文件有所不同,这时候我们可以独自定义横屏与竖屏的布局文件( 文件名字要一样),默认情况是加载layout目录里的布局文件。同样应用还要支持不同的语言,如果我们应用里没有定义手机所用语言的资源时,会默认加载values的值。

    要使程序适应布局,则需要添加以下两个目录:layout-land 和 layout-port ,系统在进行改变的时候,将会根据这两个现在的屏幕的横竖分别读取这两种不同的布局方式,如果这当前的不存在,则会根据layout中的布局进行布局。

    下面是我的的三个布局:

    layout:

    代码
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical" android:layout_width="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView android:layout_width="fill_parent" android:id="@+id/text1"
    android:layout_height
    ="wrap_content" android:text="@string/hello" />
    <Button android:id="@+id/btn1" android:text="坚"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    <Button android:id="@+id/btn2" android:text="横"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    </LinearLayout>
    layout-land:

    代码
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical" android:layout_width="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView android:layout_width="fill_parent"
    android:layout_height
    ="wrap_content" android:text="横屏显示" />
    <TextView android:layout_width="fill_parent" android:id="@+id/text1"
    android:layout_height
    ="wrap_content" android:text="@string/hello" />
    <Button android:id="@+id/btn1" android:text="横"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    <Button android:id="@+id/btn2" android:text="竖"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    </LinearLayout>

    显示效果:

    layout-port:

    代码
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical" android:layout_width="fill_parent"
    android:layout_height
    ="fill_parent">
    <TextView android:layout_width="fill_parent"
    android:layout_height
    ="wrap_content" android:text="坚屏显示" />
    <TextView android:layout_width="fill_parent" android:id="@+id/text1"
    android:layout_height
    ="wrap_content" android:text="@string/hello" />
    <Button android:id="@+id/btn1" android:text="横"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    <Button android:id="@+id/btn2" android:text="竖"
    android:layout_width
    ="fill_parent" android:layout_height="wrap_content">
    </Button>
    </LinearLayout>

    显示效果:

    下面是对内容的显示进行的国际化:

    需要添加以下目录:

    values-zh-rCN 此下面放置的是显示中文内容的

    values-zh-rTW 此下显示繁体中文

    values-jp  显示日文

    一般形式为:values-国家编号

    这些显示将根据操作系统的语言进行读取,如果不存在相应的语言版本,将会直接获取values中的内容:

    在此中,只对中文进行了设置

    values中的内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="hello">Hello World, ShowTask!</string>
    <string name="app_name">ShowTask</string>
    </resources>
    values-zh-rCN 中的内容如下:

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
    <string name="hello">此程序用于显示任务!</string>
    <string name="app_name">显示任务</string>
    </resources>
    显示效果如下:

    参考文章:

    http://www.android123.com.cn/androidkaifa/206.html

  • 相关阅读:
    程序员深夜惨遭老婆鄙视,原因竟是CAS原理太简单?| 每一张图都力求精美
    微前端大赏
    【老李瞎折腾】001、折腾一下DDNS
    【老李瞎折腾】000、使用树莓派搭建自己的服务器
    【老李瞎折腾】目录
    RGB打水印在YUV图片上
    BMP格式解析
    测试开发不会前端?ElementUI你需要了解一下
    如何通过命令行运行Postman脚本2020-09-15
    长点心吧!测试老鸟教你如何避免背锅
  • 原文地址:https://www.cnblogs.com/fly_binbin/p/1921378.html
Copyright © 2011-2022 走看看