Pixel-Perfect UI in the WebView

Unity游戏上架微信小游戏:攻克4MB首包限制的实战优化指南 在移动端游戏开发中,资源管理与性能优化是核心技术挑战,尤其在WebGL环境下,内存与包体限制更为严格。其原理在于通过代码裁剪、资源压缩与动态加载等技术,在有限资源内实现最佳用户体验。对于Unity开发者而言,掌握这些技术能显著提升游戏在微信小游戏等平台的兼容性与启动速度。其中,AssetBundle资源分包与纹理压缩是关键实践,例如必须使用LZ4而非LZMA压缩AssetBundle以避免内存峰值,同时采用ASTC等格式优化纹理资源。这些方法共同解决了首包体积控制、渲染效率及平台适配等核心问题,最终确保游戏 阅读详情
最近谷歌的服务器一直被墙,访问不方便,把经常看到的文章转到这里,方便看,做andriod WebApp这几篇文章是必看的!原文https://developer.chrome.com/multidevice/webview/pixelperfect


Pixel-Perfect UI in the WebView

There are a number of options you can use to create the perfect UI, this article will outline some of the best practices for the mobile web in general and then some specific tricks you could use for hybrid applications.

The viewport meta tag is of the most important tags you need to add to your web app. Without it, the WebView may act as if your site is designed for desktop browsers. This causes your web page to be given a larger width (typically 980px) and scales it to fit the WebView’s width. In most cases, the result is a tiny overview version of the page that requires the user to pan and zoom to actually read content, like the image on the left.

If you want the width of your site to be 100% of the WebView’s width, as shown on the right, you need to set the viewport meta tag:

<meta name="viewport" content="width=device-width, initial-scale=1">

Setting width to the special value device-width will give you more control over the page layout.

By default the WebView will set the viewport to device-width, rather than defaulting to a desktop viewport. However, for reliable and controlled behaviour it’s good practice to include the viewport meta tag.

In some cases, you may need to display content that isn’t designed for mobile devices – for example, if you’re displaying content you don’t control. In this case, you need to force the WebView to use a desktop-size viewport:

If these methods are not set and no viewport is specified, the WebView will try and set the viewport width based on the content size.

In addition to doing this, you may want to use the new layout algorithm TEXT_AUTOSIZINGintroduced in Android 4.4, which increases the font size to make it more readable on a mobile device. See setLayoutAlgorithm.

Responsive design is the notion of changing your UI depending on the dimensions of the screen size. Here we will look at some simple examples of how you can adapt your UI and images, but if you want to dig in to other topics then this article on HTML5Rocks is a good point of reference.

One of the main CSS features you’ll want to use is media queries.

A media query is a way of applying CSS to elements based on a device’s characteristics. For example, suppose you wanted to go from a vertical layout to a horizontal layout based on orientation.

First, set CSS properties to default to portrait:

.page-container {
    display: -webkit-box;
    display: flex;

    -webkit-box-orient: vertical;
    flex-direction: column;

    padding: 20px;
    box-sizing: border-box;
}

Then to switch to a horizontal layout you just need to switch the flex-direction property based on the orientation:

@media screen and (orientation: landscape) {
  .page-container.notification-opened {
    -webkit-box-orient: horizontal;
    flex-direction: row;
  }

  .page-container.notification-opened > .notification-arrow {
    margin-right: 20px;
  }
}

This technique can be used to change layout based on the width of the screen.

For example, adjusting the size of the button from being 100% to something smaller as the physical screen size gets larger.

button {
  display: block;
  width: 100%;
  ...
}

@media screen and (min-width: 500px) {
  button {
    width: 60%;
  } 
}

@media screen and (min-width: 750px) {
  button {
    width: 40%;
    max-width: 400px;
  } 
}

These are minor changes, but depending on your UI, media queries can help you to make much larger changes to appearance of your application, while keeping the same HTML.

Tip: Try to change the UI based on width as a component starts to look out of place, rather than focusing on device sizes. By doing this, your app will look great on a range of devices, not just the ones you test on. An easy way to do this is play around with the size of a browser window. But remember that actual devices have different screen densities than your monitor, so always test on a range of devices.

For more on designing for mobile devices, see HTML5Rocks.

The variety of screens sizes and densities also presents challenges for images. Smaller images require less memory and are faster to load, but blur if you scale them up.

The images below show the blurring that occurs when you scale a low-density image up for a high-denity screen, compared with the crisp display of an appropriately-sized image.

Here are a few tips and tricks to make sure your images look crisp and clear on any screen:

  • Use CSS for scalable effects.
  • Use vector graphics.
  • Provide high-resolution photos.

Make use of CSS3 where you can for borders, drop shadows, border-radius, and so on instead of images. These features can scale easily. However, some combinations of CSS properties can be expensive to render, so you should always test the specific combinations you’re using. (For some sample data on fast and slow CSS properties, see: CSS Paint Times and Page Render Weight on HTML5Rocks.)

Scalable Vector Graphics (SVGs) are a great way of providing scalable version of images. For images that are well-suited to vector graphics, SVG provides high quality images with very small file sizes. For more information, see Splash Vector Graphics on your Responsive Site on HTML5Rocks.

Use a version suitable for a high-DPI device and scale the image using CSS. This way the image has a high quality across devices. If you use high compression (low quality setting) when generating the image, you may be able to acheive good visual results with a reasonable file size.

This approach is simple, but has a couple of potential downsides: highly-compressed images may show some visual artifacts, so you need to experiment to determine what level of compression you find acceptable. And resizing the image in CSS can be an expensive operation.

If high compression is not suitable for your needs, try the WebP format, which gives a high quality image with relatively small file size. See the official WebP site for details. Don’t forget that you’ll need to provide a fallback for older versions of Android where WebP isn’t supported.

For more information on this topic:

In many cases, you can’t use a single image for all devices. In this case, you can select different images based on the screen size and density. You can use media queries to select background images by screen size and density. You can also use JavaScript to control how images load.

To select an image based on the screen density, you need to use dpi or dppx units in your media query. The dpi unit represents dots per CSS inch, while dppx represents dots per CSS pixel.

Looking at the table below you can see the relation between dpi and dppx. 1dppx is equivalent to 96dpi, 2dppx == 192dpi == 2 x 96dpi, and so on.

Device pixel ratioGeneralized screen densityDots per CSS inch (dpi)Dots per CSS pixel (dppx)
1xMDPI96dpi1dppx
1.5xHDPI144dpi1.5dppx
2XHDPI192dpi2dppx

The generalized screen density buckets are defined by the Android native platform and are used in other places to express screen density (for example, http://screensiz.es).

You can use media queries to assign background images to elements. For example, if you have a logo image with 256px x 256px size on a device with a pixel ratio of 1.0, you might use the following CSS rules:

.welcome-header > h1 {
  flex: 1;

  width: 100%;

  max-height: 256px;
  max-width: 256px;

  background-image: url('../images/html5_256x256.png');
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

To swap this out for a larger image on devices with device pixel ratio of 1.5 (hdpi) and 2.0 (xhdpi), you can add the following rules:

@media screen and (min-resolution: 1.5dppx) {
  .welcome-header > h1{
      background-image: url('../images/html5_384x384.png');
  }
}

@media screen and (min-resolution: 2dppx) {
  .welcome-header > h1{
      background-image: url('../images/html5_512x512.png');
  }
}

You can then merge this technique with other media queries like min-width, which is useful as you start to account for different form factors.

@media screen and (min-resolution: 2dppx) {
  .welcome-header > h1{
          background-image: url('../images/html5_512x512.png');
  }
}

@media screen and (min-resolution: 2dppx) and (min-width: 1000px) {
  .welcome-header > h1{
          background-image: url('../images/html5_1024x1024.png');

          max-height: 512px;
      max-width: 512px;
  }
}

You might notice that the max-height and max-width are set to 512px for 2ddpx resolution, with an image of 1024x1024px. this is because a CSS “pixel” actually takes into account the device pixel ratio (512px * 2 = 1024px).

The web today doesn’t have a solution for this. There are some proposals in the works, but they aren’t available in current browsers or in the WebView.

In the mean time, if you generate your DOM in JavaScript, you can create multiple image resources in a sane directory structure:

images/
    mdpi/
        imagename.png
    hdpi/
        imagename.png
    xhdpi/
        imagename.png

Then use the pixel ratio to try and pull the most appropriate image:

function getDensityDirectoryName() {
  if(!window.devicePixelRatio) {
    return 'mdpi';
  }

  if(window.devicePixelRatio > 1.5) {
    return 'xhdpi';
  } else if(window.devicePixelRatio > 1.0) {
    return 'hdpi';
  }

  return 'mdpi';
}

The alternative to implementing the above in JS, is to alter the base URL of the page to define the relative URLs for images.

<!doctype html>
<html class="no-js">
<head>
  <script>
    function getDensityDirectoryName() {
      if(!window.devicePixelRatio) {
          return 'mdpi';
      }

      if(window.devicePixelRatio > 1.5) {
          return 'xhdpi';
      } else if(window.devicePixelRatio > 1.0) {
          return 'hdpi';
      }

      return 'mdpi';
    }

    var baseUrl = 
        'file:///android_asset/www/img-js-diff/ratiores/'+getDensityDirectoryName()+'/';
    document.write('<base href="'+baseUrl+'">');
  </script>

    ...
</head>

<body>
    ...
</body>
</html>

The major downsides to this are that it blocks the page load and forces you to use absolute paths for scripts, CSS files, links and so on, since the base URL points to a density-specific directory.

Perfetto UI分析Native内存:看懂四个关键视图,揪出Android应用里的“隐形”泄漏点 本文深入解析Perfetto UI在Android Native内存泄漏分析中的应用,通过四大核心视图(Unreleased malloc size、Total malloc size、Unreleased malloc count、Total malloc count)帮助开发者精准定位内存泄漏点。文章详细介绍了各视图的解读策略、联合分析技巧及实战案例,为Android性能优化提供专业指导。 阅读详情

相关推荐

ChatGPT-PerfectUI:开源前端界面深度解析与部署实战

在现代Web开发中,React、TypeScript与Tailwind CSS构成了构建复杂应用的主流技术栈。React的组件化思想天然契合动态UI的构建,TypeScript则通过静态类型检查提升了大型项目的代码可靠性,而Tailwind CSS的原子化设计极大提升了样式开发效率与一致性。这些技术的组合为开发高性能、可维护的前端应用提供了坚实基础,尤其在需要处理实时数据流与复杂状态管理的场景中价值显著。以AI对话应用为例,一个优秀的前端不仅需要流畅渲染流式消息,还需实现高效的会话管理、消息编辑与丰富的交互

weixin_28718641的博客 304

Perfetto学习大全

Perfetto 是一个功能强大的性能分析和追踪工具,主要用于捕获和分析复杂系统中的事件和性能数据,特别是在 Android 和 Linux 环境下。它的核心目标是帮助开发者深入了解系统和应用程序的运行状态,以便优化性能和诊断问题。

执剑人 4063

Pixel perfect precision

在UI UX方面 深入浅出的书籍, 书内很直观的讲解了,在产品设计中需要注意的点以及相应原理。

Perfetto 命令行工具(Android 10 及更高版本)

在 Android 设备上收集性能信息。确保设备已连接,然后选择“添加 ADB 设备”。一旦您的设备 已成功配对(您可能需要在设备上允许USB调试),选择“开始录制”按钮。可能会有更多可用数据源,具体取决于您的设备、操作系统版本以及内核。如果不确定,请首先打开“CPU”选项卡下的“计划详细信息”。通过进程统计信息数据源,您可以获取有关系统和各个进程的轮询计数器。借助 heapprofd,您可以对使用本地内存的原因进行采样。,然后从左侧菜单中选择“记录新跟踪”。,包括调用堆栈的 Java 框架。

许浑的博客 4352

tkinter表格进阶:5分钟实现CSV数据可视化编辑界面(含右键菜单配置)

本文详细介绍了如何使用Python的tkintertable库快速构建CSV数据可视化编辑界面。通过导入导出CSV数据、深度定制右键菜单(如复制、插入行、删除行)以及实现单元格验证等进阶功能,开发者能在5分钟内创建一个可嵌入自动化流程的专业级桌面数据编辑工具,显著提升数据处理效率。

933

开源收银系统_大型收银系统源码_OctShop

开源收银系统正成为大型连锁企业数字化转型的关键工具。相比传统闭源系统,开源方案具有成本低(年均降本60%+)、定制灵活(支持多业态协同)、自主可控等优势,能有效解决高并发、多门店数据同步等痛点。核心价值在于:1)分布式架构适配规模化扩张;2)模块化设计实现个性化开发;3)开放接口打通ERP/CRM等系统。典型案例显示,连锁商超通过源码二次开发实现库存实时同步,补货效率提升50%;餐饮集团统一多业态收银流程后会员复购率增长35%。选型需关注源码成熟度、技术兼容性和安全合规,建议采用"开源+服务商&q

OctShop全栈工程师 946

Perfetto分析进阶

一、Perfetto介绍Perfetto是AndroidQ中引入的全新下一代平台级跟踪工具,为Android、Linux和Chrome平台提供了一种通用的性能检测和跟踪分析工具集。其核心是引入了一种全新的用户空间到用户空间的跟踪协议,该协议基于protobuf序列化机制将抓取的数据填充到共享内存缓冲区,可用于获取平台内部的内置数据源(例如ftrace、atrace、logcat),也提供了SDK...

内核工匠 3万+

数字IC后端时钟树综合实战:OCC电路优化与时钟树平衡策略

本文深入探讨了数字IC后端设计中时钟树综合的关键挑战,重点分析了OCC电路时钟树优化的必要性。通过实战案例,详细阐述了如何通过手动干预、时钟分组与分段长树等策略,避免工具自动平衡导致的时序违例和资源浪费,从而有效实现时钟树平衡并提升设计质量。

weixin_29306261的博客 339

【免费下载】 Perfetto UI插件开发指南:扩展性能分析工具的可视化能力

Perfetto作为一款强大的性能分析工具,其UI界面提供了灵活的插件机制,允许开发者扩展其功能。本文将深入解析Perfetto UI插件的开发流程、生命周期和扩展点,帮助开发者快速掌握插件开发技巧。 ## 开发环境准备 在开始开发Perfetto插件前,需要配置以下环境: 1. 操作系统要求:MacOS或Linux 2. 安装必要的构建依赖项 3. 克隆Perfetto项目代码 ```b...

gitblog_00371的博客 663

一步步指导:在Chrome中安装Vue插件vue-devtools

Vue.js是现代Web开发中最流行的前端框架之一,它以其轻量级、高性能和易于理解的设计理念受到开发者的喜爱。为了更高效地开发和调试Vue应用,Vue.js官方提供了一个强大的开发工具——vue-devtools。

小透明的博客 5625

关于并网继电器的继电器自检逻辑及实现方式

对于常规的光伏并网逆变器来说,继电器控制至关重要。继电器一般位于逆变电感后,共模电感前,用于将逆变电压与电网电压脱开,一般国外有双继电器的安规强制认证要求,国内目前只需要单继电器要求(后续应该会有双继电器要求,个人感觉)

weixin_29982209的博客 2630

全新下一代平台级跟踪工具:Perfetto使用指南

System Tracing&#34;系统跟踪&#34;就是记录一段时间内的设备活动。系统跟踪会生成跟踪文件,该文件可用于生成系统报告。此报告可帮助开发者了解如何最有效地提升应用或游戏的性...

音视频开发进阶 1万+

保姆级避坑指南:在Win10/Win11上搞定西门子博图V17完整安装(附注册表清理技巧)

本文提供了一份详细的西门子博图V17在Win10/Win11系统上的安装指南,涵盖从系统预检、注册表清理到分步安装的全过程。特别针对常见的安装失败问题,如PendingFileRenameOperations注册表残留和.NET Framework 3.5未启用等,提供了专业的解决方案和避坑技巧,帮助用户高效完成安装并优化性能。

weixin_29240711的博客 962

Android性能优化工具

使用HierarchyViewer分析UI性能 我们可以通过SDK提供的工具HierarchyViewer来进行UI布局复杂程度及冗余等分析,如下: xxx@ThinkPad:~$ hierarchyviewer //通过命令启动HierarchyViewer11 选中一个Window界面item,然后点击右上方Hierarchy window或者Pixel Perfect wi

icewst的专栏 993

国产安全芯片在密码算法国密体系下的性能适配策略

国密体系即国家商用密码体系,是保障信息安全的核心技术体系。自20世纪90年代末起步,国密体系经历了从无到有、从弱到强的发展历程。1999年,国家密码管理局成立,标志着国密体系的正式建立。2000年,国密SM1算法首次发布,开启了国密算法的标准化进程。此后,SM2、SM3、SM4等算法陆续推出,形成了完整的对称与非对称密码算法体系。:2010年,国密标准正式纳入国家标准体系,国密算法在金融、政务、通信等关键领域的应用得到明确规范。

qq_40552871的博客 1361

AndroidKiller之APK 编译失败,无法继续下一步签名【BUG解决】【App反向解析】

文章目录项目场景:问题描述原因分析:解决方案:BUG解决 项目场景: AndroidKiller: 在反向解析APP包时报错:APK 编译失败,无法继续下一步签名。 网上很多方法都是无效的哈,我追究原因发现,这个bug的出现大部分情况都是因为Apktool的问题。 此方法:百分之百解决此bug! 错误如下: 问题描述 APK 编译失败,无法继续下一步签名! 原因分析: Apktool版本不适配的问题,现在的技术更新换代太快,我们安装AndroidKiller的时候,有时候不是官方渠道的话,他的版本是非常

一键难忘的博客 2万+

Perfetto使用教程

三种录制设置,适用不同的使用场景对应代码中 Trace.beginSection/ATRACE_BEGIN 记录的事件,选中后会显示黑色边框。

Hfengxiang的博客 2418

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

【Android 性能分析】第五天:Perfetto UI分析CPU

Perfetto UI是一款基于浏览器的系统级性能分析工具,可解析CPU调度、内存分配等数据,提供应用-系统-硬件全链路分析。支持多种trace文件格式,具有交互灵活、跨平台等特点。使用前需通过Android Studio Profiler或命令行生成trace文件。核心操作包括导入文件、主界面解析及交互技巧(缩放、搜索、轨道管理等)。典型分析场景包括CPU负载均衡、线程调度状态及方法耗时分析,帮助定位性能问题。

u012739527的博客 2253

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Perfetto使用

6. 手机上开发者选项---》系统跟踪--》显示"快捷设置"图块,打开后,下拉菜单会出现一个小虫子图标。点击小虫子图标就可以开始抓取日志了,再次点击停止抓取日志,长按图标回到系统跟踪界面。自动录制完成后会自动打开展示在网页上,如果stop按钮一直在执行,但是没有进度展示,那就是有问题的。但是有时候会有问题, 提示adb kill-server ,但是依旧没有反应,可以重新打开新的网站。跟踪文件可以分享或者保存到本地,pull出来后使用perfetto工具查看。方法3:将配置保存为文件,执行脚本抓取。

derek的专栏 1038

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

【Perfetto】Perfetto 零基础入门

Perfetto 是一个用于性能检测和跟踪分析的生产级开源堆栈。它提供用于记录系统级和应用程序级跟踪的服务和库、本机 + java 堆分析、使用 SQL 分析跟踪的库以及用于可视化和探索多 GB 跟踪的基于 Web 的 UI。

天天的博客 1757

性能分析工具 之 Perfetto基本使用

Perfetto是很好的性能分析工具,发展很快。它不仅可以看systrace,也可以将logcat也一起提取出来,方便与其他信息放在同一个时间轴上去分析。它也可以分析memory问题,如ion 和dma_buf 泄露。Perfetto是一个高效的性能分析工具,可以提高程序员分析问题的效率,希望大家可以掌握。

qrx941017的博客 4万+

一款Android性能分析神器!Perfetto(建议收藏)

借助config文件配置要调试的内容,命令行如下,其中 config.pbtx为config file,可以借助 Perfetto UI的 recording setting( Perfetto UI)生成,或者在 Perfetto UI中的 redording settings中设置后好,在 recording command中 copy所有内容,在 terminal中直接 copy执行即可。它还具有其他功能,包括计算摘要度量,使用用户友好的描述注释跟踪以及从跟踪的内容派生新事件。

Hfengxiang的博客 4324

Android性能分析工具-Perfetto基本使用

Perfetto 是一个用于性能检测和跟踪分析的生产级开源堆栈。它提供用于记录系统级和应用级跟踪的服务和库、本机 + Java 堆分析、使用 SQL 分析跟踪的库以及用于可视化和探索多 GB 跟踪的基于 Web 的 UI。

adorable_的博客 1万+

线下场景-UI(systrace + perfetto)

线下场景我们能直接连接设备debug,所以监控纬度很多,我们从4个方面入手(就像是中医的望闻听切)来介绍相关监控工具的使用。(如果你已经很熟悉的话,可以直接跳过) 1.UI 2.CPU 3.内存 4.整体 在下面的章节会逐一介绍,本节先介绍UI。 本节我们主要介绍可以用来分析UI的工具 systrace和Perfetto。 这两个工具都是Android系统提供的系统追踪工具,可追踪/监控应用各个方面的数据,包括CPU、内存、view、IO等,其中Perfetto是Android 10(API 29)推出的,

mydream___anjie的博客 2647

Perfetto详细解析

Perfetto 是一个生产级的开源堆栈,用于提高性能 仪器和痕量分析。与 Systrace 不同,它提供数据源超集,可以用 protobuf 编码的二进制流形式记录任意长度的跟踪记录。可以将Perfetto理解为systrace的升级版,用在更新的平台、新图表展示更多的信息。

weixin_43700867的博客 7558

【PerfettoDocs】UI插件开发

本文翻译自以下链接:https://perfetto.dev/docs/contributing/ui-pluginsUI插件允许开发者直接将新的可视化功能与分析工具集成到Perfetto界面中。通过利用丰富的扩展点,插件能够针对特定使用场景对Perfetto进行个性化定制。本指南提供了关于如何创建并向Perfetto贡献UI插件的完整操作说明。若您是首次参与 Perfetto 贡献,请先参阅《》,然后再学习《注意:当前所有插件均为内置形式,即它们位于开源的Perfetto代码库中,并与托管在。

wuweikai0617的博客 163
上一篇: window.outerWidth in mobile browsers
下一篇: 快乐Node码农的十个习惯
offbye
offbye 领域专家: 操作系统技术领域 领域专家: 操作系统技术领域
博客等级 码龄24年 1309粉丝 252原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址