How does one use Resources.getFraction()
来源:互联网 发布:孚盟软件logo 编辑:程序博客网 时间:2024/04/29 20:55
转:http://stackoverflow.com/questions/11734470/how-does-one-use-resources-getfraction
How do I store a fractional value like 3.1416
in resources? What to write in the XML and how to retrieve it in Java code?
The documentation for getFraction()
states:
public float getFraction (int id, int base, int pbase)
Retrieve a fractional unit for a particular resource ID.
Parameters
base
The base value of this fraction. In other words, a standard fraction is multiplied by this value.pbase
The parent base value of this fraction. In other words, a parent fraction (nn%p) is multiplied by this value.Returns
Attribute fractional value multiplied by the appropriate base value
This answer shows a simple example of percentages without going into the details of what the arguments mean.
1 Answer
You specify fractions in XML as so:
<item name="fraction" type="fraction">5%</item> <item name="parent_fraction" type="fraction">2%p</item>
Where 5% would be 0.05 when actually used.
Then:
// 0.05fgetResources().getFraction(R.fraction.fraction, 1, 1);// 0.02fgetResources().getFraction(R.fraction.parent_fraction, 1, 1);// 0.10fgetResources().getFraction(R.fraction.fraction, 2, 1);// 0.10fgetResources().getFraction(R.fraction.fraction, 2, 2);// 0.04fgetResources().getFraction(R.fraction.parent_fraction, 1, 2);// 0.04fgetResources().getFraction(R.fraction.parent_fraction, 2, 2);
As you can see, depending on the type of fraction, the getFraction
method multiples the values accordingly. If you specify a parent fraction (%p
), it uses the second argument (pbase
), ignoring the first. On the other hand, specifying a normal fraction, only the base
argument is used, multiplying the fraction by this.
- How does one use Resources.getFraction()
- How does one actually use the splitter control?
- How does Zend View use view helpers?
- how does Interface Wrapper promote re use / ease of use of interface class
- JNDI Resources HOW-TO
- How one VBA project can use an object declared in the class module of another project
- How does netstat work
- How Does it End()?
- How does XVCL work?
- How does JNA work?
- How does cas work
- how does wifi work?
- How MySQL Does Sorting
- how does RemoteFX works?
- How does google work
- How does browsersync work?
- How does maven work?
- How to close resources properly
- 匿名项目连载(三)--->说说列表
- C# 基本运算符重载
- Android BitmapShader 实战 实现圆形、圆角图片
- python数据库操作-MySQL,SQLite
- 用Scala调用MLLib之二元分类
- How does one use Resources.getFraction()
- windows下安装apache
- POJ 2190 ISBN
- ScrollView 内置 Webview导致底部页面下方空白区域无限下滑
- Oracle修改字段类型方法总结
- Android Xfermode 实战 实现圆形、圆角图片
- OC初识
- 如何在Windows下利用Oracle VM VirtualBox虚拟机下安装linux
- 在jsp中如何实现网页的自动更新