当前位置:网站首页>21 Days Learning Challenge - Day 1 Punch (Screen Density)
21 Days Learning Challenge - Day 1 Punch (Screen Density)
2022-08-02 10:40:00 【Meng Fangfang】
1. Recall
I have been engaged in Android development for a few years. Looking back now, I was very happy when I first started to display a few simple controls, then I came into contact with the four major components of Android, then I customized View, and finally I used a third-party open source framework.Do a few functions that I think are cool... and then it seems to stop, and for several years in the middle, I "wasted my life" with this basic thing...
It wasn't until the first two years that I realized that it couldn't go on like this. If I just knew about the ever-changing technology, but I didn't know why, it would soon be eliminated, so I started to study the source code.As soon as I researched the source code, I found that I didn't seem to know anything, and I was in the confusion of just entering the industry...
Take advantage of the 21-day learning challenge opportunity, force yourself to learn hard for 21 days with the great God!
Day 1: Pixel density, screen density, resolution.
2. Background:
In order to adapt to different screen sizes, during the Android development process, you need to add multiple pictures of ldpi, mdpi, nodpi, xhdpi, xxhdpi, xxxhdpi to the resource file.
3. Several concepts
①Screen size
Screen size refers to the physical size of the phone diagonally, in inches (inch), one inch is about 2.54 cm.
General mobile phone sizes are 4 inches, 4.5 inches, 5.0 inches, 5.2 inches, 5.4 inches, 5.99 inches, 6.0 inches, 6.2 inches, etc.
②Screen resolution
Resolution is the total number of pixels on the screen of a mobile phone. Generally, the number of pixels in the screen width is multiplied by the number of pixels in the screen height.The larger the resolution, the more delicate the screen and the more details that can be displayed.
Commonly used resolutions are 320x240, 640x480, 1280x720, 1280x960, 1080x1920, 2560x1440, etc. The unit is pixel.For example, 1080x1920 means that there are 1080 pixels in the width direction of the screen and 1920 pixels in the height direction of the screen.
Get screen resolution:
int screenWidth = getWindowManager().getDefaultDisplay().getWidth(); // screen width
int screenHeight = getWindowManager().getDefaultDisplay().getHeight(); // screen height
③Pixel density
Pixel density (dpi, dots per inch; or PPI, pixels per inch) refers to the number of pixels per inch.
④Screen density:
Screen density is actually another representation of pixel density, based on 160dpi=1.0.After the mobile phone leaves the factory, the screen density, including the pixel density in the X and Y axis directions, is a fixed value.
Android divides the screen based on the pixel density of 160dpi. When the pixel density is 160dpi, the screen density is 1.0, when the pixel density is 120dpi, the screen density is 0.75, and when the pixel density is 320dpi, the screen density is 2.0.
Android divides the actual screen density into low, medium, high, and extra high, extra extra high.
General screen: ldpi is 120dpi, mdpi is 160dpi, hdpi is 240dpi, xhdpi is 320dpi, xxhdpi is 480dpi.
Get pixel density and screen density:
DisplayMetrics dm = new DisplayMetrics();
dm = getResources().getDisplayMetrics();
float density = dm.density; // screen density (pixel ratio: 0.75/1.0/1.5/2.0)
int densityDPI = dm.densityDpi; // pixel density (pixels per inch: 120/160/240/320)
float xdpi = dm.xdpi; //Pixel density in the X-axis direction
float ydpi = dm.ydpi; //Pixel density in the Y-axis direction
screenWidth = dm.widthPixels; // screen width
screenHeight = dm.heightPixels; // screen height
4. How to load multiple drawables
When the android system adapts to the drawable, it will first look in the dpi directory corresponding to the device.If it is not found, it will follow the principle of "first high then low", and then scale the image proportionally.
For example, it is currently an xhdpi device (there are only xxhdpi, xhdpi, xxhdpi, nodpi, mdpi, hdpi in the project), then the search sequence for drawables is: first search for the xhdpi directory, if not found, then search for xxhdpi, if not found, thenFind xxxhdpi, find nodpi if you haven't found it, find hdpi if you haven't found it, find mdpi if you can't find it, and search in turn.If the target image is found in xxhdpi, it will be compressed by 2/3 for use (because the system thinks it has found an image larger than the appropriate size), if the image is found in mdpi, it will be enlarged by 2 times to use (the system thinks it has found a picture)A picture smaller than the suitable size needs to be enlarged to ensure normal).
边栏推荐
- 牛客刷题——剑指offer(第三期)
- 8年软件测试工程师的感悟:与薪资相匹配的永远是实力
- 21天学习挑战赛--第一天打卡(屏幕密度)
- LayaBox---TypeScript---Three slash instructions
- 21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
- 3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
- Geoffery Hinton: The Next Big Thing in Deep Learning
- Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
- logo 图标(php图片加文字水印)
- 身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
猜你喜欢

Mysql环境变量的配置(详细图解)

The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit

DVWA Clearance Log 2 - Command Injection

STM32+MPU6050设计便携式Mini桌面时钟(自动调整时间显示方向)

Verilog的随机数系统任务----$random

深度学习100例 —— 卷积神经网络(CNN)实现mnist手写数字识别

MySql tens of millions of paging optimization, fast insertion method of tens of millions of data

外包学生管理系统架构文档

如何在技术上来保证LED显示屏质量?

零代码工具推荐---HiFlow
随机推荐
WPF 截图控件之文字(七)「仿微信」
超赞!发现一个APP逆向神器!
博云入选Gartner中国DevOps代表厂商
牛客刷题——剑指offer(第三期)
LayaBox---TypeScript---JSX
Verilog的随机数系统任务----$random
C#/VB.NET 添加多行多列图片水印到Word文档
使用较广泛的安全测试工具有哪些?
21天学习挑战赛--第一天打卡(屏幕密度)
深度学习100例 —— 卷积神经网络(CNN)实现mnist手写数字识别
一体化在线政务服务平台,小程序容器技术加速建设步伐
详细总结SoC、DSP、MCU、GPU和FPGA等基础概念
The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
365天挑战LeetCode1000题——Day 047 设计循环队列 循环队列
LayaBox---TypeScript---三斜线指令
情景剧《重走长征路》上演
How to choose a truly "easy-to-use, high-performance" remote control software
R language ggplot2 visualization: based on the fill parameter and shape parameter in the aes function, custom draw a grouped line chart and add data points (scatter points), use the legend.position fu
Event object, do you know it well?