摘要:由于設備眾多繁雜,尺寸各有不一,所以的適配也必將任重道遠。支持的屬性目前還在完善支持的布局和。詳細的配置和使用詳見綜上分析從程序的穩(wěn)定適用性個人覺得還是通過創(chuàng)建不同的資源文件來適配比較穩(wěn)妥。
由于Android設備眾多繁雜,尺寸各有不一,所以android的適配也必將任重道遠。
綜合了一下目前主要的android適配方案主要有以下幾種:
創(chuàng)建不同的資源文件 values-1920x1080,values-1280x720等等
2.百分比布局支持庫使用谷歌正式提供的百分比布局支持庫(percent-support-lib),它提供兩種布局
PercentFrameLayout,PercentRelativeLayout支持的屬性有:
layout_widthPercent layout_heightPercent layout_marginPercent layout_marginLeftPercent layout_marginTopPercent layout_marginRightPercent layout_marginBottomPercent layout_marginStartPercent layout_marginEndPercent
例子: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"
android:clickable="true">
但是百分比庫還是存在一些問題:
當使用圖片時,無法設置寬高的比例
比如我們的圖片寬高是200*100的,我們在使用過程中我們設置寬高為20%、10%,這樣會造成圖片的比例失調(diào)。為什么呢?因為20%參考的是屏幕的寬度,而10%參考的是屏幕的高度。
2.很難使用百分比定義一個正方形的控件
比如,我現(xiàn)在界面的右下角有一個FloatingActionButton,我希望其寬度和高度都為屏幕寬度的10%,很難做到。
3.一個控件的margin四個方向值一致
有些時候,我設置margin,我希望四邊的邊距一致的,但是如果目前設置5%,會造成,上下為高度的5%,左右邊距為寬度的5%。
綜合上述這些問題,可以發(fā)現(xiàn)目前的percent-support-lib并不能完全滿足我們的需求,
3.Android AutoLayout適配方式一款第三方的支持庫
AutoLayout所用單位px:這里的px并非是Google不建議使用的px,在內(nèi)部會進行轉化處理。
支持的屬性:
layout_width
layout_height
layout_margin(left,top,right,bottom)
pading(left,top,right,bottom)
textSize
maxWidth, minWidth, maxHeight, minHeight
目前還在完善支持的布局和view。
詳細的配置和使用詳見https://github.com/hongyangAndroid/AndroidAutoLayout
從程序的穩(wěn)定適用性個人覺得還是通過創(chuàng)建不同的資源文件來適配比較穩(wěn)妥。
---以上個人根據(jù)網(wǎng)絡資源總結整理,經(jīng)驗不足,歡迎多多指教---
文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉載請注明本文地址:http://systransis.cn/yun/65362.html
閱讀 5297·2021-09-22 15:59
閱讀 1878·2021-08-23 09:42
閱讀 2574·2019-08-29 18:42
閱讀 3459·2019-08-29 10:55
閱讀 2072·2019-08-27 10:57
閱讀 1771·2019-08-26 18:27
閱讀 2733·2019-08-23 18:26
閱讀 2931·2019-08-23 14:40