Android-xliff
先看以下这个案例,然后在分析:
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的更多相关文章
- android xml中的xliff属性
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:xliff=" ...
- <Android 基础(十八)> XLIFF
介绍 XLIFF ,XML Localization Interchange File Format,XML本地化数据交换格式. 实际使用 1.布局文件 activity_main.xml <? ...
- Android中string.xml中的的标签xliff:g(转载)
转自:http://blog.csdn.net/xuewater/article/details/25687987 在资源文件中写字符串时,如果这个字符串时动态的,又不确定的值在里面,我们就可以用xl ...
- android nfc中MifareClassic格式的读写
Android支持的数据格式 数据格式的Intent filter AndroidManifest.xml文件中,要像向下列示例那样,在<activity>元素内的<meta-dat ...
- 【转】Android NFC学习笔记
一:NFC的tag分发系统 如果想让android设备感应到NFC标签,你要保证两点 1:屏幕没有锁住 2:NFC功能已经在设置中打开 当系统检测到一个NFC标签的时候,他会自动去寻找最合适的acti ...
- <xliff:g>标签
摘要: 这是Android4.3Mms源码中的strings.xml的一段代码: <!--Settings item desciption for integer auto-delete sms ...
- Android NFC开发概述
NFC手机相比普通手机来说,有以下3个附加功能: 1.可以当成POS机来用,也就是“读取”模式 2.可以当成一张卡来刷,也就是NFC技术最核心的移动支付功能 3.可以像蓝牙.Wi-Fi一样做点 ...
- 修改Android系统字号(一)
/*********************************************************************** * 修改Android系统字号(一) * 说明: * ...
- 在Android中访问内置SE和基于SE的卡模拟(一)
2013-10-10 编写 前言 在“十问Android NFC手机上的卡模拟”文中仅仅简单的介绍了一下相关的概念,如果需要了解基于SE的卡模拟的更多细节,也就是,究竟在Android的NFC手机上, ...
- Android的TextView使用Html来处理图片显示、字体样式、超链接等
一.[Android实例]实现TextView里的文字有不同颜色 转eoe:http://www.eoeandroid.com/thread-4496-1-1.html import android. ...
随机推荐
- R语言读取Hive数据表
R通过RJDBC包连接Hive 目前Hive集群是可以通过跳板机来访问 HiveServer, 将Hive 中的批量数据读入R环境,并进行后续的模型和算法运算. 1. 登录跳板机后需要首先在Linux ...
- 20172306 《Java程序设计》第二周学习总结
20172306<Java程序设计>第二周学习总结 教材学习内容总结 这一周的学习,我觉得我比上一周认真多了,而且我突然发现慢慢学习的过程中,以前有一些多余自己打出来的东西,有了更清晰的认 ...
- post方式发送请求报文
$url="http://www.test.com/04_demo_weather.php?id=5"; $ci=curl_init($url); curl_setopt($ci, ...
- \\Device\\PhysicalMemory
从Windows Server 2003 with SP1 以后就禁用了用户态访问\\Device\\PhysicalMemory,要访读取SMBIOS的信息,请使用以下API:•EnumSystem ...
- virualbox问题
出不来64位虚拟系统 bios设置虚拟化可用 2.创建虚拟机 启动不了 提示 不能打开一个... 安装exten 扩张包 3.设备 -- 安装增强功能... 分辨率 设置成功
- 企业官网原型制作分享-Starbucks
星巴克是全球著名的咖啡连锁店,星巴克的产品不单是咖啡,咖啡只是一种载体.而正是通过咖啡这种载体,星巴克把一种独特的格调传送给顾客.咖啡的消费很大程度上是一种感性的文化层次上的消费,文化的沟通需要的就是 ...
- React中使用CSS
第一种: 在组件中直接使用style 不需要组件从外部引入css文件,直接在组件中书写. import React, { Component } from "react"; con ...
- is not allowed to connect to this MySQL server解决办法
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; myuser:代表你 ...
- SpringBoot中文乱码解决方案
转载:https://blog.csdn.net/wangshuang1631/article/details/70753801 方法一,修改application.properties文件 增加如下 ...
- 回文日期(NOIP2016)
题目:回文日期 这题虽然说不难,但是也不能算水了. 我先讲讲思路.60分的算法很好写,就是判断一下是不是回文串,分离每个数位,判断即可. 但我们的目标是满分,所以我来讲讲满分算法. 首先,给的是区间, ...