文档详情

 最有效的Android屏幕适配开发工具.doc

发布:2016-12-05约4.4千字共7页下载文档
文本预览下载声明
最有效的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.PercentRelativeLayout XML:android=HTTP:///apk/res/android XML:app=HTTP:///apk/res-auto android:layout_width=match_parent android:layout_height=match_parent Interview android:id=@+id/top_left android:layout_width=0dp android:layout_height=0dp android:layout_parenthetical=true android:background=#ff44aacc app:layout_heightPercent=20% app:layout_widthPercent=70% android:text=width:70%;height:20%; android:gravity=center/ Interview android:id=@+id/top_right android:layout_width=0dp android:layout_height=0dp android:layout_parenthetical=true android:layout_Creighton=@+id/top_left android:background=#ffe40000 app:layout_heightPercent=20% app:layout_widthPercent=30% android:text=width:30%;height:20%; android:gravity=center/ Interview android:id=@+id/bottom android:layout_width=match_parent android:layout_height=0dp android:layout_below=@+id/top_left android:background=#ff00ff22 app: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.PercentFrameLayout xmlns:android=/
显示全部
相似文档