android中的Plurals(Quantity Strings)类型
不同的语言对数量的定义有不同的语法规则。例如,在英语中,1个指的是一种特殊情况。其他时候我们说n个。这种单数和复数的情况非常的普通。但其他语言却有明显的区别。Android中设置了0,1,2,"很少",“许多”和“其他”做为数量表述。
对于给定的语言和数量,决定使用那种情况是非常的困难和复杂的。Android提供了getQuantityString()来帮助我们决定选择适当的资源。
语法:
<?xml version="1.0" encoding="utf-8"?> <resources> <plurals name="plural_name"> <item quantity=["zero" | "one" | "two" | "few" | "many" | "other"] >text_string</item> </plurals> </resources>
文件位置:res/values/filename.xml
如何引用:R.plurals.plural_name
例子:
<? xml version = "1.0" encoding = "utf-8" ?><resources>
<plurals name = "numberOfSongsAvailable" >
<item quantity = "one" > One song found. </item>
<item quantity = "other" > %d songs found. </item>
</plurals>
</resources>