屏幕适配问题
来源:互联网 发布:极品飞车ol车辆数据 编辑:程序博客网 时间:2024/06/05 03:12
以下根据谷歌官方的文档
Android categorizes device screens using two general properties: size and density. You should expect that your app will be installed on devices with screens that range in both size and density. As such, you should include some alternative resources that optimize your app’s appearance for different screen sizes and densities.
There are four generalized sizes: small, normal, large, xlargeAnd four generalized densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)
android 适配:为不同的屏幕大小设置不同的布局,为不同的屏幕设置不同的图片大小;
Each layout should be saved into the appropriate resources directory, named with a -<screen_size> suffix. For example, a unique layout for large screens should be saved under res/layout-large/
布局的格式一般是layout-large,layout-small等,但要求放置在里面的xml文件的名字是一致的,同时还可以设置横竖屏时的布局,横屏的标志是-land,竖屏protrait是默认的
MyProject/ res/ layout/ # default (portrait) main.xml layout-land/ # landscape main.xml layout-large/ # large (portrait) main.xml layout-large-land/ # large landscape main.xml
Create Different Bitmaps
To generate these images, you should start with your raw resource in vector format and generate the images for each density using the following size scale: xhdpi: 2.0 hdpi: 1.5 mdpi: 1.0 (baseline) ldpi: 0.75This means that if you generate a 200x200 image for xhdpi devices, you should generate the same resource in 150x150 for hdpi, 100x100 for mdpi, and 75x75 for ldpi devices.Then, place the files in the appropriate drawable resource directory:MyProject/ res/ drawable-xhdpi/ awesomeimage.png drawable-hdpi/ awesomeimage.png drawable-mdpi/ awesomeimage.png drawable-ldpi/ awesomeimage.pngAny time you reference @drawable/awesomeimage, the system selects the appropriate bitmap based on the screen's density.
我们在bitmap这个实体类图片时,要在drawable的不同dpi像素密度中放置不同大小的图片,转换的倍数关系在文档中有说明如上;
在Google官方开发文档中,说明了 mdpi:hdpi:xhdpi:xxhdpi:xxxhdpi=2:3:4:6:8 的尺寸比例进行缩放。例如,一个图标的大小为48×48dp,表示在mdpi上,实际大小为48×48px,在hdpi像素密度上,实际尺寸为mdpi上的1.5倍,即72×72px,以此类推。
Note: Low-density (ldpi) resources aren’t always necessary. When you provide hdpi assets, the system scales them down by one half to properly fit ldpi screens.
ldpi中的图片一般是不用的,如果用到,系统会默认选择hdpi的一半大小去适配
官方API提供的一些方法
Use “wrap_content” and “match_parent”//
Use RelativeLayout//使用相对布局
Use Size Qualifiers//针对不同布局把大小固定死
Use Nine-patch Bitmaps//使用点九图
使用dp sp不使用px//sp:Scale-Independent Pixels的缩写,可以根据文字大小首选项自动进行缩放。Google推荐我们使用12sp以上的大小,通常可以使用12sp,14sp,18sp,22sp,最好不要使用奇数和小数。
现在又有了百分比布局,谷歌官方提供的PercentRelativeLayout,直接设置控件占据的百分比大小,不用考虑适配的问题
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"/> <ImageView app:layout_widthPercent="50%" app:layout_heightPercent="50%" app:layout_marginTopPercent="25%" app:layout_marginLeftPercent="25%"/> </android.support.percent.PercentFrameLayout/>
- 屏幕适配问题
- 屏幕适配问题
- 屏幕适配问题
- 屏幕适配问题
- 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- Android屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- Android 屏幕适配问题
- android 屏幕适配问题
- android 屏幕适配问题
- Ubuntu 16.04 安装后优化
- Centos7下通过Zabbix自动发现并监控硬盘
- Leetcode 101 Symmetric Tree
- oracle定时导出脚本
- 判断一个字符串是另外字符串的旋转字符串
- 屏幕适配问题
- oracle数据类型和对应的java类型
- codeforces 697D Puzzles (树形dp 期望 推荐)
- 2016/11/30 14:59 一个失败人生的开始
- 创建Libevent库
- Html 显示图片流
- fastcgi介绍
- 实现堆栈中最小的元素getMin()
- EXTJS4.2.1学习(二)