先上图
这仨赏金猎人App解决方案 赏金猎人开发日志地址/posts/3203,我想问问谁有办法替换系统默认的尺寸计算方案求大佬告知
这个是实现渲染
这个是UI设计图
使用方法
RpxUtil.rpx(23,this.context) 直接按照UI尺寸调用即可
源码
package com.example.shangjinlieren.utils;import ohos.agp.window.service.Display;import ohos.agp.window.service.DisplayManager;import ohos.app.Context;public class RpxUtil {private static float WIDTH=750;private static float HEIGHT=1334;public static float rpx(int value, Context context){float wRatioValue= (getDisplayWidthInPx(context)/WIDTH)*value;float hRatioValue= ( getDisplayHeightInPx(context)/HEIGHT)*value;float h =0;if (value<=750){h= wRatioValue;}else if (value>750){h=hRatioValue;}return h;}/*** 获取屏幕宽度** @return 屏幕宽度*/public static int getDisplayWidthInPx( Context context) {Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();return display.getAttributes().width;}/*** 获取屏幕高度,不包含状态栏的高度* @return 屏幕高度,不包含状态栏的高度*/public static int getDisplayHeightInPx( Context context) {Display display = DisplayManager.getInstance().getDefaultDisplay(context).get();return display.getAttributes().height;}}