01.27 Android屏幕適配解決方案

一、支持各種屏幕尺寸

1、使用wrap_content、match_parent、weight

Weight計算出的寬度= 控件原來寬度+剩餘空間所佔百分比的寬度

假設屏幕寬度為 L

Button1 2/3L = L +(L-2L)*1/3 = L-1/3L=2/3L

Button2 1/3L = L+(L-2L)*2/3 = L-2/3L= 1/3L

Android屏幕適配解決方案

效果

假設兩個 button width 等於0dp,則Button1 1/3L = 0 +L*1/3 = 1/3L ;Button2 = 2/3L = 0 +L*2/3 = 2/3L

2、使用相對佈局,禁用絕對佈局

3、使用限定符

尺寸限定符(android 3.2及之前),如res/layout-large/main.xml,res/layout/main.xml。

最小寬度限定符(android 3.2之後),res/layout-sw600dp/main.xml,res/layout/main.xml。

方向限定符,res/values-sw600dp-port/layouts.xml,res/values-sw600dp-land/layouts.xml

4、使用自動拉伸位圖,可以根據控件大小自動拉伸

左上:拉伸區域;右下:間隔區域

Android屏幕適配解決方案

拉伸位圖

Android屏幕適配解決方案

效果圖

二、支持各種屏幕密度

1、使用密度非制約像素 ,解決寬度不一致問題

Android屏幕適配解決方案

不同屏幕尺寸下的像素定義

2、提供備用位圖,否則會造成內存佔用問題:圖片如分辨率不匹配會造成內存猛增

Android屏幕適配解決方案

針對不同dpi提供位圖

三、實施自適應用戶界面流程

1、確定當前佈局

2、根據當前佈局做出響應

3、重複使用其他活動中的片段

4、處理屏幕配置變化

四、最佳實踐

1、針對不同屏幕尺寸設計高清圖片

2、代碼動態設置尺寸


分享到:


相關文章: