美文网首页
鸿蒙appUI布局适配原有的设计

鸿蒙appUI布局适配原有的设计

作者: iOS开发小学生 | 来源:发表于2024-10-22 15:52 被阅读0次

1.创建一个ArkTS工具文件 DisPlayInfo

import {display} from '@kit.ArkUI'

class DisPlayInfo {
  private screenWidth = 0;
  private screenHeight = 0;
  private static readonly STANDARD_WIDTH = 750;
  private static readonly STANDARD_HEIGHT = 1334;

  constructor() {
    let screenWidth = display.getDefaultDisplaySync().width;
    let screenHeight = display.getDefaultDisplaySync().height;
    this.screenWidth = Math.min(screenWidth, screenHeight);
    this.screenHeight = Math.max(screenWidth, screenHeight);
    console.info("screenWidth " + screenWidth + " screenHeight " + this.screenHeight)
  }

  public getWidth(width: number): PX {
    let realWidth: number = Math.floor(width * this.screenWidth / DisPlayInfo.STANDARD_WIDTH)
    return `${realWidth}px`
  }

  public getHeight(height: number): PX {
    return `${Math.floor((this.screenHeight / DisPlayInfo.STANDARD_HEIGHT) * height)}px`
  }

}

export default new DisPlayInfo();

2.在需要使用的ArkTS文件里

2.1引入工具文件
import DisPlayInfo from '../../util/DisPlayInfo'

2.2在使用的地方
Image(this.bannerImage)
  .width(DisPlayInfo.getWidth(88))
  .height(DisPlayInfo.getWidth(88))
  .objectFit(ImageFit.Fill)

相关文章

  • 10086 APP设计、标注规范

    这一套移动视觉APPUI设计规范,包含了界面布局、颜色、文字规范、按钮规范、图标规范、图片规范、列表规范、控件规范...

  • webApp 页面布局

    1. 流式布局 概念:流式布局是页面元素宽度按照屏幕分辨率进行适配调整,但是整体布局不变。 设计方法:布局都是通...

  • libGdx计算广告高度

    lbGdx的适配是通过标准设计的720x1280或者1080x1920计算布局,根据高适配或者宽适配,也可以简单理...

  • 2020-10-30 web移动端

    web移动端 1.重点:适配 2.目标:掌握4种适配方案 ( 流式布局、弹性布局、响应式布局、像素适配(rem适配...

  • App适配

    布局适配 字体适配 软键盘适配

  • 移动端、PC端屏幕适配

    移动端适配 页面引入ydui.flexible.js页面布局采用rem布局rem计算方式:设计图尺寸px / 10...

  • 性能优化 - 布局适配与图片适配

    1. 布局适配 布局适配,其实就是布局别名问题: 平板 layout-sw600dp (600dp以上):平...

  • .学会了吗?

    看看这9组Banner设计,是如何兼容不同的尺寸,学会适配,更重要的是学会版式布局的设计思维方式。 By Ambe...

  • Day11 鸿蒙,2.0版本支持两大全新布局!

    前面我的文章介绍了鸿蒙Harmony的定向布局(DirectionalLayout)、从属布局(Dependent...

  • 移动端开发

    视口 屏幕适配 布局 流体布局 响应式布局 rem布局 弹性盒模型布局

网友评论

      本文标题:鸿蒙appUI布局适配原有的设计

      本文链接:https://www.haomeiwen.com/subject/ebsrdjtx.html