Android螢幕適配的乙個另類方法

2021-08-03 07:33:45 字數 2428 閱讀 5265

關於android手機螢幕適配,我至今沒找到乙個合適的方法....於是自己想了乙個歪招。

原理也比較簡單,例如大多手機的標準解析度是1920 * 1080或1280 * 720

但是遇到1800 * 1080或1184 * 720的就麻煩了(何況有些手機還有虛擬按鍵狀態列),其實也簡單,把1800當1920來用,1184當1280來用就ok了

使用**如下:

//寬度預設為null既是全滿,在findviewbyid時去適配,最後得到適配成功的view物件

imageview img_two= (imageview) (screenutils.

setviewheight

(context, findviewbyid(r.id.img_two),null, 0.16f);

本人菜鳥,大家有更好的方法,歡迎指點....

/**

* view比例適配

*@return

*/public staticview setviewheight(context context,finalview view, float width,floatheight)else if(screenutils.gettotalheight(context) > 1100 && screenutils.gettotalheight(context) < 1280)else

if(width ==null)

if(view.getparent().getclass().tostring().equals("class android.widget.relativelayout"))

if(view.getparent().getclass().tostring().equals("class android.widget.framelayout"))

}else

if(view.getparent().getclass().tostring().equals("class android.widget.relativelayout"))

if(view.getparent().getclass().tostring().equals("class android.widget.framelayout"))

}return null;

}

/**

* 獲得螢幕寬度

* *

@param

context

*@return

*/public static intgetscreenwidth(context context)

/***

@param

context

*@return

獲取螢幕內容高度不包括虛擬按鍵

*/public static intgetscreenheight(context context)

/***

@param

context

*@return

獲取螢幕原始尺寸高度,包括虛擬功能鍵高度

*/public static intgettotalheight(context context)catch(exception e)

returndpi;

}

Android螢幕適配篇(一)

螢幕的尺寸 指的是螢幕對角線的長度,單位是英吋 1英吋 2.54厘公尺 常見的螢幕尺寸有 4.0,5.0,5.5,6.0,8.0,10.0等,平時我們說你手機又多大,這裡指的就是螢幕尺寸。螢幕解析度指的是螢幕上橫向,縱向上的畫素點數量。單位是px,1px 1個畫素點。我們通常以橫向畫素 縱向畫素來表...

Android的螢幕適配

所以就像是你去公司面試,第一印象也是很重要滴 本質1 使得布局元素自適應螢幕尺寸 開發中,我們使用的布局一般有 由於絕對布局 absolutelayout 適配性極差,所以極少使用。對於線性布局 linearlayout 相對布局 relativelayout 和幀布局 framelayout 需要...

乙個巨集解決 iOS螢幕適配

用乙個巨集 解決 ios各種機型的螢幕適配問題 前提條件 設計師給出的效果圖應以iphone6p為基準。什麼時候使用這個巨集?所有控制項的尺寸 x值y值,cell的高度,文字的字型大小 如何使用這個巨集?在 supporting files 資料夾中的 prefixheader.pch 編寫 def...