最有效的Android屏幕适配开发工具.doc
文本预览下载声明
最有效的Android屏幕适配开发工具
文/腾讯优测 吴宇焕
相信开发同学都被安卓设备碎片化的问题折磨过,市面上安卓手机的主流屏幕尺寸种类繁多,给适配造成很大的困难。就算搞定了屏幕尺寸问题,各种分辨率又让人眼花缭乱,当你走出了前面所说的两大坑,很有可能又掉进“屏幕长宽比不同”的陷阱。。。
说多了都是泪,我就想做一名安静的开发怎么这么难?
经历过无数次跌跌撞撞,我总结出一些经验,想与大家一起分享。
已知的屏幕适配方法:
(1)按像素比:y/开发时用的屏幕像素=x/用户设备像素
(2)按长度:用dip(假设屏幕尺寸基本不变)
(3)按密度:放在l、m、h文件夹(假设屏幕尺寸基本不变,dpi越大 PX越大)
而Android 5.0 Google官方推出了百分比布局支持库,意在解决大部分屏幕适配的问题。下面我就向大家详细介绍一下:
Google百分比布局支持库
(1)支持的布局
布局 PercentRelativeLayout PercentFrameLayout
(2)支持的属性
属性 layout_widthPercent layout_heightPercent layout_marginPercent layout_marginLeftPercent layout_marginTopPercent layout_marginRightPercent layout_marginBottomPercent layout_marginStartPercent layout_marginEndPercent
(3)使用方法
1、加载android-support-percent-lib
dependencies {compile com.android.support:percent:22.2.0}
2、PercentRelativeLayout
?xml version=1.0 encoding=utf-8?android.support.percent.PercentRelativeLayoutXML:android=HTTP:///apk/res/androidXML:app=HTTP:///apk/res-autoandroid:layout_width=match_parentandroid:layout_height=match_parentInterviewandroid:id=@+id/top_leftandroid:layout_width=0dpandroid:layout_height=0dpandroid:layout_parenthetical=trueandroid:background=#ff44aaccapp:layout_heightPercent=20%app:layout_widthPercent=70%android:text=width:70%;height:20%;android:gravity=center/Interviewandroid:id=@+id/top_rightandroid:layout_width=0dpandroid:layout_height=0dpandroid:layout_parenthetical=trueandroid:layout_Creighton=@+id/top_leftandroid:background=#ffe40000app:layout_heightPercent=20%app:layout_widthPercent=30%android:text=width:30%;height:20%;android:gravity=center/Interviewandroid:id=@+id/bottomandroid:layout_width=match_parentandroid:layout_height=0dpandroid:layout_below=@+id/top_leftandroid:background=#ff00ff22app:layout_heightPercent=80%android:text=width:100%;height:80%;android:gravity=center//android.support.percent.Hyperventilation
3、PercentFrameLayout
?xml version=1.0 encoding=utf-8?android.support.percent.PercentFrameLayoutxmlns:android=/
显示全部