先看以下这个案例,然后在分析:

string.xml 使用xliff,需要导入命名空间 xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"

<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <string name="app_name">UI_All</string>

    <!-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 以下是浮点型系列 -/>
<!- 显示浮点类型 %n$mf m=1.2小数点后面有两位 -->
<string name="cost_money" msgid="7137320847812992243">花费<xliff:g id="number">%1$1.2f</xliff:g>块</string> <!-- 显示浮点类型 %n$mf m=1.3小数点后面有三位-->
<string name="cost_money_2">您消费了<xliff:g id="number2">%1$1.3f</xliff:g>元</string> <!-- 显示浮点类型 %n$mf m=1.9小数点后面有九位-->
<string name="cost_money_3">您支付了<xliff:g id="number3">%1$1.9f</xliff:g>元钱</string> <!-- 显示浮点类型 %n$mf m=9.5小数点后面有五位 9.5的9理解位空格 -->
<string name="cost_money_4">您扣除了<xliff:g id="number4">%1$9.5f</xliff:g>元钱</string> <!-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 以下是整型系列 -->
<string name="count">这个办公室有<xliff:g id="count">%1$d</xliff:g>个工程师</string>
<string name="count2">这个办公室有<xliff:g id="count2">%1$9d</xliff:g>个工程师</string> <!-- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 以下是字符串型系列 -->
<string name="string">请求网络读取交易信息异常,详情是<xliff:g id="string">%1$s</xliff:g>行号890行</string>
<string name="string2">此书名是<xliff:g id="string2">%1$9s</xliff:g>设计模式书籍</string> <!-- 多个xliff 由于多个xliff 和 显示类型无关,以下就随意以浮点型 示例 -->
<string name="total_points">\t第一名<xliff:g id="t1">%1$1.2f</xliff:g>分\n\t第二名<xliff:g id="t2">%2$1.2f</xliff:g>分</string>
<string name="welcome">
欢迎 <xliff:g id="name">%1$s</xliff:g>, 排名 <xliff:g id="num">%2$d</xliff:g>
</string> </resources>

activity_stirng.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="20dp"> <!-- 以下是整数系列>>>>>>>>>>>>>>>>>> -->
<!-- 浮点型,小数点后面三位 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cost_money" /> <TextView
android:id="@+id/tv_info1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="浮点型,小数点后面两位"
/> <TextView
android:id="@+id/tv_info2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="浮点型,小数点后面三位"
/> <TextView
android:id="@+id/tv_info3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="浮点型,小数点后面九位"
/> <TextView
android:id="@+id/tv_info4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="浮点型,小数点后面五位,有空格 m=9.5 9代表空格"
/> <!-- 以下是整数系列>>>>>>>>>>>>>>>>>> -->
<TextView
android:id="@+id/tv_info5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="整数"
android:layout_marginTop="40dp"
/> <TextView
android:id="@+id/tv_info6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="整数有空格"
android:layout_marginTop="20dp"
/> <!-- 以下是字符串系列>>>>>>>>>>>>>>>>>> -->
<TextView
android:id="@+id/tv_info7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="字符串"
/> <TextView
android:id="@+id/tv_info8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="字符串 有空格"
/> <!-- 以下是多个xliff -->
<TextView
android:id="@+id/tv_info9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="以下是多个xliff"
/>
<TextView
android:id="@+id/tv_info10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="以下是多个xliff 欢迎"
/> </LinearLayout>

Activity

package liudeli.ui.all;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView; public class StringActivity extends Activity { private TextView tv_info1, tv_info2, tv_info3, tv_info4,
tv_info5, tv_info6, tv_info7, tv_info8, tv_info9,
tv_info10; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_string); tv_info1 = findViewById(R.id.tv_info1);
tv_info2 = findViewById(R.id.tv_info2);
tv_info3 = findViewById(R.id.tv_info3);
tv_info4 = findViewById(R.id.tv_info4);
tv_info5 = findViewById(R.id.tv_info5);
tv_info6 = findViewById(R.id.tv_info6);
tv_info7 = findViewById(R.id.tv_info7);
tv_info8 = findViewById(R.id.tv_info8);
tv_info9 = findViewById(R.id.tv_info9);
tv_info10 = findViewById(R.id.tv_info10); initStringData();
} @SuppressLint("StringFormatMatches")
protected void initStringData() { String cost1 = getString(R.string.cost_money, 5.5);
tv_info1.setText(cost1); String cost2 = getString(R.string.cost_money_2, 22.99);
tv_info2.setText(cost2); String cost3 = getString(R.string.cost_money_3, 88.77);
tv_info3.setText(cost3); String cost4 = getString(R.string.cost_money_4, 88.77);
tv_info4.setText(cost4); String cost5 = getString(R.string.count, 200);
tv_info5.setText(cost5); String cost6 = getString(R.string.count2, 600);
tv_info6.setText(cost6); String cost7 = getString(R.string.string, "严重的内存溢出(原因-图片申请控件过大");
tv_info7.setText(cost7); String cost8 = getString(R.string.string2, "大话");
tv_info8.setText(cost8); String cost9 = getString(R.string.total_points, 539.81, 695.99);
tv_info9.setText(cost9); String s = getString(R.string.welcome, "abc", 123);
tv_info10.setText(s); }
}

效果:


分析:

%n$md:输出的是整数,n代表是第几个参数,设置m的值可以在输出之前放置空格,也可以设为0m,在输出之前放置m个0 

以下代码会报错❌,因为整数这种方式,m不能等于 9.9 不能是浮点型,可以是9

<string name="count2">这个办公室有<xliff:g id="count2">%1$9.9d</xliff:g>个工程师</string>

以下代码是正确的✅

<string name="count2">这个办公室有<xliff:g id="count2">%1$9d</xliff:g>个工程师</string>

%n$mf:输出的是浮点数,n代表是第几个参数,设置m的值可以在输出之前放置空格,设置m的值可以控制小数位数,如m=2.2时,输出格式为00.00

以下代码是正确的✅

<string name="cost_money_4">您扣除了<xliff:g id="number4">%1$9.5f</xliff:g>元钱</string>

以下代码是错误的❌,设置后,无空格效果,m必须是浮点型,整型无效果

<string name="cost_money_4">您扣除了<xliff:g id="number4">%1$9f</xliff:g>元钱</string>

%n$ms:输出的是字符串,n代表是第几个参数,设置m的值可以在输出之前放置空格

以下代码是没有空格:%1$s

<string name="string2">此书名是<xliff:g id="string2">%1$s</xliff:g>设计模式书籍</string>

以下代码是有空格的:%1$9s

<string name="string2">此书名是<xliff:g id="string2">%1$9s</xliff:g>设计模式书籍</string>

以下代码是有空格的:%1$9.9s 效果和 %1$9s 是一样的空格量

<string name="string2">此书名是<xliff:g id="string2">%1$9.9s</xliff:g>设计模式书籍</string>

Android-xliff的更多相关文章

  1. android xml中的xliff属性

    <resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff=" ...

  2. <Android 基础(十八)> XLIFF

    介绍 XLIFF ,XML Localization Interchange File Format,XML本地化数据交换格式. 实际使用 1.布局文件 activity_main.xml <? ...

  3. Android中string.xml中的的标签xliff:g(转载)

    转自:http://blog.csdn.net/xuewater/article/details/25687987 在资源文件中写字符串时,如果这个字符串时动态的,又不确定的值在里面,我们就可以用xl ...

  4. android nfc中MifareClassic格式的读写

    Android支持的数据格式 数据格式的Intent filter AndroidManifest.xml文件中,要像向下列示例那样,在<activity>元素内的<meta-dat ...

  5. 【转】Android NFC学习笔记

    一:NFC的tag分发系统 如果想让android设备感应到NFC标签,你要保证两点 1:屏幕没有锁住 2:NFC功能已经在设置中打开 当系统检测到一个NFC标签的时候,他会自动去寻找最合适的acti ...

  6. <xliff:g>标签

    摘要: 这是Android4.3Mms源码中的strings.xml的一段代码: <!--Settings item desciption for integer auto-delete sms ...

  7. Android NFC开发概述

    NFC手机相比普通手机来说,有以下3个附加功能:  1.可以当成POS机来用,也就是“读取”模式   2.可以当成一张卡来刷,也就是NFC技术最核心的移动支付功能  3.可以像蓝牙.Wi-Fi一样做点 ...

  8. 修改Android系统字号(一)

    /*********************************************************************** * 修改Android系统字号(一) * 说明: * ...

  9. 在Android中访问内置SE和基于SE的卡模拟(一)

    2013-10-10 编写 前言 在“十问Android NFC手机上的卡模拟”文中仅仅简单的介绍了一下相关的概念,如果需要了解基于SE的卡模拟的更多细节,也就是,究竟在Android的NFC手机上, ...

  10. Android的TextView使用Html来处理图片显示、字体样式、超链接等

    一.[Android实例]实现TextView里的文字有不同颜色 转eoe:http://www.eoeandroid.com/thread-4496-1-1.html import android. ...

随机推荐

  1. LibreOJ #2006. 「SCOI2015」小凸玩矩阵 二分答案+二分匹配

    #2006. 「SCOI2015」小凸玩矩阵 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据   题目描述 ...

  2. Vsphere初试——架设Panabit行为管理

    Panabit是目前国内X86平台单板处理能力最高(双向40G).提供免费版本(软件形态),是以DPI为核心优势并发展起来的最专业.上线效果最好.性价比最高的新一代应用网关.Panabit流控引擎,基 ...

  3. 前端js数据排序

    销量统计系统中国地图热力分布图需要显示一个各省区销量列表,并按从多到少排序.本着轻易不修改后台数据源的原则,决定在前端进行修改实现.其实也容易实现,将数据存放一个数据<省区名称,销量>,然 ...

  4. solr之创建core(搜索核心,包括索引和数据)的方法

    我的solrhome为D:\solrHome\solr step1:进入solrHome会看到collection1文件夹,创建该文件夹的副本,重命名为product 进入product文件夹,进入d ...

  5. Java类加载机制及自定义加载器

    转载:https://www.cnblogs.com/gdpuzxs/p/7044963.html Java类加载机制及自定义加载器 一:ClassLoader类加载器,主要的作用是将class文件加 ...

  6. Find the location of libmysqlclient.so.X file in Linux environments

    I'm putting together a script that has a requirement of knowing libmysqlclient.so.[15|16|18] .so fil ...

  7. HTML-入门篇day01

    HTML-入门篇day01 1.web     C/S:Client Server    客户端 服务器    QQ,...    B/S:Browser Server    浏览器 服务器 PC机: ...

  8. google pay app权限使用说明

    android.permission.CAMERA. 个人中心使用头像时需要使用该权限. android.permission.READ_PHONE.获取用户DeviceId,作为用户单点登录唯一值.

  9. HTML5 通过 FileReader 实现文件上传

    概述 在页面中上传时,之前一般都是需要使用form表单进行上传.html5 中提供了FileReader 可以将文件转换成Base64编码字符串,因此就可以直接使用 AJAX实现文件上传. 实现代码 ...

  10. Everything的简单使用

    1.Everythings下载地址: http://www.voidtools.com/ 下载完后直接解压,运行everything.exe即可打开使用: 2.基本设置 (1)去除不需要搜索的文件夹: ...