当前位置: 首页 > news >正文

Android R.fraction

来源

我是在看Android10原生代码,绘制状态栏蓝牙电量相关类中第一次看到R.fraction的,如类BatteryMeterDrawable

<fraction name="battery_button_height_fraction">10%</fraction>

mButtonHeightFraction = context.getResources().getFraction(
                R.fraction.bt_battery_button_height_fraction, 1, 1);

方法解释

public float getFraction(@FractionRes int id, int base, int pbase) 
源码中方法解释如下:
Retrieve a fractional unit for a particular resource ID.
Params:
id – The desired resource identifier, as generated by the aapt tool. This integer encodes the package, type, and resource entry. The value 0 is an invalid identifier. 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.
Throws:
Resources.NotFoundException – Throws NotFoundException if the given ID does not exist.

用处

我自己没用过,待补充

测试

分别测试fraction的两种声明:有p的跟没p的

<item name="fraction" type="fraction">30%</item>
<item name="fraction" type="fraction">30%p</item>

测试没p的:

测试案例1:保持第三个参数不变

测试:

        //<item name="fraction" type="fraction">30%</item>float fraction1 = this.getResources().getFraction(R.fraction.fraction, 1, 1);float fraction2 = this.getResources().getFraction(R.fraction.fraction, 2, 1);float fraction3 = this.getResources().getFraction(R.fraction.fraction, 3, 1);float fraction4 = this.getResources().getFraction(R.fraction.fraction, 4, 1);

结果:

分析:

都是30%乘以第二个参数(base)

 测试案例1:第三个参数改变

 测试:

        //<item name="fraction" type="fraction">30%</item>float fraction1 = this.getResources().getFraction(R.fraction.fraction, 1, 2);float fraction2 = this.getResources().getFraction(R.fraction.fraction, 1, 3);float fraction3 = this.getResources().getFraction(R.fraction.fraction, 2, 2);float fraction4 = this.getResources().getFraction(R.fraction.fraction, 2, 3);

结果:

分析:

都是30%乘以第二个参数(base)

 总结以上两个测试案例可知:在没p的情况下,getFraction方法返回的结果就是乘以第二个参数;

测试有p的:

 测试:

        //<item name="fraction" type="fraction">30%p</item>float fraction1 = this.getResources().getFraction(R.fraction.fraction, 1, 2);float fraction2 = this.getResources().getFraction(R.fraction.fraction, 1, 3);float fraction3 = this.getResources().getFraction(R.fraction.fraction, 2, 2);float fraction4 = this.getResources().getFraction(R.fraction.fraction, 2, 3);

结果:

分析:

都是30%乘以第三个参数(pbase)

http://www.lryc.cn/news/228118.html

相关文章:

  • C语言精华题目锦集1
  • 头歌答案Python——JSON基础
  • TDengine 与煤科院五大系统实现兼容性互认,助力煤矿智能化安全体系搭建
  • 231030期就业班开班咯!我在前方护航,让你稳稳入职
  • 小白学安全-漏洞编号的理解 CVE/CAN/BUGTRAQ/CNCVE/CNVD/CNNVD
  • 助力燃气安全运行:智慧燃气管网背景延展
  • 低代码、零代码开源与不开源:区别解析
  • LabVIEW中如何在网络上使用远程VI服务器
  • Centos 7rc.local脚本命令开机不执行及指定用户启动的方法
  • mysql 的存储过程
  • http客户端简单demo
  • 解决UniAD在高版本CUDA、pytorch下运行遇到的问题
  • ADC、DMA以及串口之间的联系和区别?
  • jupyter lab配置列表清单
  • 爱发电 OAuth 登录 SDK for Remix
  • Wpf 使用 Prism 实战开发Day05
  • 性能压测工具:Locust详解
  • vmware 修改主机名称 hadoop 服务器环境配置(一)
  • 淘宝店铺订单插旗接口(taobao.trade.memo.update淘宝店铺订单交易备注修改接口)
  • py文件如何打包成exe?如何压缩文件大小?
  • SQL优化相关(持续更新)
  • Linux学习--limits文件配置详解
  • Android Studio 代码上传gitLab
  • 【避雷选刊】Springer旗下2/3区,2个月录用!发文量激增,还能投吗?
  • Linux常用的压缩命令
  • 如何为VM虚拟机添加D盘
  • C# 16进制颜色转为RGB颜色
  • 【工具】Java计算图片相似度
  • GDB调试
  • swift和OC混编报错问题