android density

article/2025/10/11 3:47:23

为什么要引入dip

—The reason for dip to exist is simple enough. Take for instance the T-Mobile G1. It has a pixel resolution of 320x480 pixels. Now image another device, with the same physical screen size, but more pixels, for instance 640x480. This device would have a higher pixel density than the G1.

—If you specify, in your application, a button with a width of 100 pixels, it will look at lot smaller on the 640x480 device than on the 320x480 device. Now, if you specify the width of the button to be 100 dip, the button will appear to have exactly the same size on the two devices.

—The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, the baseline density assumed by the platform (as described later in this document). At run time, the platform transparently handles any scaling of the dip units needed, based on the actual density of the screen in use. The conversion of dip units to screen pixels is simple: pixels = dips * (density / 160). For example, on 240 dpi screen, 1 dip would equal 1.5 physical pixels. Using dip units to define your application's UI is highly recommended, as a way of ensuring proper display of your UI on different screens.

Screen dimensions

image

跨屏幕的两种方式

—通过系统兼容模式

—程序员控制

两种主要控制方法

—The platform provides a set of resource qualifiers that let you provide size- and density-specific resources, if needed. The qualifiers for size-specific resources are large, normal, and small, and those for density-specific resources are hdpi (high), mdpi (medium), and ldpi (low).

—The platform also provides a element, whose attributes android:largeScreens, android:normalScreens, and android:smallScreens let you specify what generalized screen sizes your application supports. A fourth attribute, android:anyDensity, lets you indicate whether or not your application includes built-in support for multiple densities.

系统做了什么

—加载资源时进行缩放处理(如图片)

—对基于象素的坐标和尺寸进行自动缩放。For instance, suppose a given device is using a WVGA high-denisty screen, which is 480x800 and about the same size as a traditional HVGA screen, but it's running an app that states that it does not support multiple densities. In this case, the system will "lie" to the application when it queries for screen dimensions, and report 320x533. Then, when the app does drawing operations, such as invalidating the rectangle from (10,10) to (100, 100), the system will likewise automatically transform the coordinates by scaling them the appropriate amount, and actually invalidate the region (15,15) to (150, 150).

—在屏幕上开辟一个“模拟器”

程序设置

image

上图是2.1版的设置画面,各版本的默认参数不大一样,1.6版以上默认全部为true,1.5版默认只有Normal screens一项为真。XML表述如下:

资源限定符

image

以指定密度启动模拟器

在命令行下运行emulator -avd youravdname -dpi-device 160

不同设置在不同密度下的结果

image

设计指导

—尽量使用wrap_content、 fill_parent 和dip。对于文字,则应该使用sp,它除了密度外还受用户偏好设置影响。

—避免使用AbsoluteLayout。

—不要直接使用象素。可使用ViewConfiguration取得系统定义的一些常量或带getScaled 前缀的方法。必须直接指定的话,可通过dip转换,如下:

final float scale = getContext().getResources().getDisplayMetrics().density;
mGestureThreshold = (int) (GESTURE_THRESHOLD_DIP * scale + 0.5f);

—使用特定密度或特定屏幕资源

BitmapFactory.Options


http://chatgpt.dhexx.cn/article/1yHKJmIY.shtml

相关文章

手游游戏资源提取 (破解、AssetStudio、VGMToolbox、disunity、Il2CppDumper、 .NET Reflector)...

参考: 公主连结 游戏资源提取(解包)简明教程 Unity3D研究院之mac上从.ipa中提取unity3D游戏资源 吾爱破解:记一次unity3d data修改 GitHub:Il2CppDumper 想拿点知名IP的手游素材做点demo,然后搜了下如何能拿到app的素材资源 一 下…

DISN:Deep Implicit Surface Network for High-quality Single-view 3D Reconstruction

时间:2019年 作者:Weiyue Wang ,University of Southern California etc. Abstract: 1.DISN 通过预测基本符号距离场来从二维图像中生成高质量的细节丰富的三维网格; 2.DISN 在二维图像上预测每一个三维点的投影位置&#xff…

Dist

这道题只要找到我们距离的规律就行了&#xff0c;我们可以发现&#xff0c;当行数小于列数时,列数(列数-1)/k,否则&#xff0c;行数(行数-1)/k&#xff0c;没记算一次我们的距离就会增加1&#xff0c;应为行数一减你就往下了一个&#xff0c;所以这个要加1. #include<bits/…

unity3D 如何提取游戏资源 (反编译)+代码反编译【P.M.出品】

转自&#xff1a;https://blog.csdn.net/LANGZI7758521/article/details/52291564 首先感谢 雨松MOMO 的一篇帖子 教我们怎么提取 .ipa 中的游戏资源。教我们初步的破解unity3d资源的基本方法 附上原帖的链接&#xff1a;http://www.xuanyusong.com/archives/2584 下面我会从头…

Unity游戏资源逆向工具

Unity游戏资源逆向工具 https://www.cnblogs.com/kekec/p/12175547.html disunity是一款Java编写&#xff08;需安装jdk1.8&#xff0c;即Java8&#xff09;的解析Unity asset和asset bundle文件&#xff08;流式加载&#xff0c;支持热更新&#xff09;的命令行工具&#xf…

Distillation

蒸馏&#xff0c;把有杂质的东西变成纯度高的 知识从教师网络集成到学生网络&#xff0c;这个过程叫迁移&#xff0c;这么做的原因是终端的算力有限&#xff0c;需要高效率 有关嵌入式开发也有教程&#xff01;&#xff01; 问题的引入&#xff1a;标签有问题&#xff0c;马更…

Unity 提取资源 Disunity、Unity Studio

提取Unity3d资源&#xff0c;用过2个工具 Disunity https://github.com/ata4/disunityUnity Studio https://github.com/RaduMC/UnityStudio 解压XXX.apk.&#xff0c;如果能在XXXX\assets\bin\Data\Managed路径下找到UnityEngine.dll&#xff0c;则表明该游戏由Unity3d打包。…

【逆向工程】 disunity的使用

1. 下载并安装好jdk: 下载地址&#xff1a;http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 安装教程&#xff1a;http://jingyan.baidu.com/article/6dad5075d1dc40a123e36ea3.html 2.下载disunity: https:/…

oracle怎么ping监听,请教TNSPING无监听的问题

请教各位高人&#xff0c;我在自己的虚拟机上装的是solaris10&#xff0c;数据库是oracle10.1.0.3.0&#xff0c;主机名如下&#xff1a; $ hostname fanww $ 在TELNET到虚拟机上之后可以正常启动监听&#xff0c;数据库也能启动&#xff0c;如下&#xff1a; $ lsnrctl start …

oracle数据库怎么ping,Oracle中tnsping命令解析

Oracle Net 工具(命令)tnsping&#xff0c;是一个OSI会话层的工具&#xff0c;它用来&#xff1a; 1)验证名字解析(name resolution&#xff0c;是oracle自己的网络服务名) 2)远程的listener是否启动 1.远程tnsping 2.关闭监听 3.启动监听&#xff0c;重新验证 总结&#xff1a…

Linux下Oracle的tnsping不显示sqlnet.ora文件路径

Tnsping在Linux与Windows下显示不一样 我的环境是&#xff1a;Centos7.6Oracle11.2.0.4 区别是&#xff1a;Linux下没有显示sqlnet.ora的路径名。 Linux下&#xff1a;Used parameter files:是空的 Windows下&#xff1a;Used parameter files显示路径名。 误导 因为我经常…

Oracle中tnsping无响应

1、tnsping 127.0.0.1&#xff08;数据库服务器地址&#xff09;无返回结果&#xff1b; 2、重启数据库服务或者重启数据库服务器问题依然不能解决&#xff1b; 3、最后发现&#xff0c;是 listener.log文件到4G了&#xff0c;删了这个文件 就正常了&#xff1b; 文件路径&…

tnsping命令解析

tnsping命令格式: tnsping <service_name> n n的意义是可以让tnsping ping多次 例: c:\Documents and Settings\Tony>tnsping orcl Oracle Net 工具&#xff08;命令&#xff09;tnsping&#xff0c;是一个OSI会话层的工具&#xff0c;它用来&#xff1a; 1&…

DOM4J及SAXReader解析xml文件数据

1、DOM4J简介 DOM4J是 dom4j.org 出品的一个开源 XML 解析包。DOM4J应用于 Java 平台&#xff0c;采用了 Java 集合框架并完全支持 DOM&#xff0c;SAX 和 JAXP。DOM4J 使用起来非常简单。只要了解基本的 XML-DOM 模型&#xff0c;就能使用。Dom&#xff1a;把整个文档作为一个…

告别996-SAXReader读取xml配置文件

在公司某一模块开发中,可以获取全部字段,但是需要取出某些不需要的字段,于是采取动态方法结合xml,将不需要的字段写在xml里面.或者根据下拉框中的值动态的获取某一个筛选条件集合sql筛选出需要的条件 前提准备 文件名:xxxxxxx.xml <?xml version"1.0" encoding…

Java 应用SAXReader 解析网络地址 XML

xml格式&#xff1a; 依赖于dom4j 框架自带该依赖包springboot框架中 工具类如下&#xff1a; import com.alibaba.fastjson.JSONObject; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader;import java.net.URL;/*** SAXReader 解析 xml 工…

XML学习总结(三)——SAXReader解析xml文件数据

第一种方式&#xff1a; 1. 加入jar包 注意 1.1 xml文件解析时编码要一致&#xff08;默认UTF-8&#xff09;&#xff0c;出现报错可以在记事本中另存为来更改编码格式。 2.2 jar包两个都需要。 2.gao.xml数据如下&#xff1a; <?xml version"1.0" encoding&qu…

SAXReader解析xml

SAXReader解析xml文件 要使用SAXReader解析xml文件&#xff0c;就需要导入两个架包&#xff1a;版本自己选择。 &#xff08;1&#xff09;dom4j-1.6.1.jar dom4j下载地址 &#xff08;2&#xff09;jaxen-1.1-beta-6.jar jaxen下载地址 项目的搭建如下&#xff1a; 项目的配置…

SAXReader的使用

一&#xff1a;导入依赖 <dependency><groupId>dom4j</groupId><artifactId>dom4j</artifactId><version>1.6.1</version> </dependency>假设xml文件内容如下 <?xml version"1.0" encoding"utf-8"?…

SAXReader解析xml文件

dom4j是Java的XML API&#xff0c;作用是读写XML文件 第1步&#xff1a;导入maven依赖 <!--测试SaxReader解析xml文件--> <dependency><groupId>dom4j</groupId><artifactId>dom4j</artifactId><version>1.6.1</version> &l…