我在改變顯示縮放的情況下計算Android N上的顯示尺寸時遇到了問題。使用變化的顯示縮放在Android N上獲取px的屏幕尺寸zoom
有了Android N,你就可以更改顯示縮放(檢查here)
但顯示尺寸(...的getSize()),如果用戶將在Android設置的變焦並沒有改變......
任何想法解決它?我是否使用px乘以scaledDensity的大小來獲得實際的顯示大小?
我的應用程序可以在px中創建窗口和組件計算屏幕尺寸,組件在服務器上進行設計。 簡單地說我在服務器上設置寬度和智能手機屏幕的寬度數學比例:
DisplayMetrics dm = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(dm);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
display.getRealSize(sizePoint);
}else{
display.getSize(sizePoint);
}
int smartphoneDisplayWidth = sizePoint.x;
int smartphoneDisplayHeight = sizePoint.y;
int serverDisplayWidth = 720px; //this come from the server
int serverComponentWidth = 720px; //this come from the server
int smartphoneComponentWidth = (smartphoneDisplayWidth/serverDisplayWidth)*serverComponentWidth;
//ex: smartphoneComponentWidth = (1080/720)*720 = 1080; the component widht on the smartphone will be 1080px.
如果設置較小的變焦我有這樣的問題:
默認:
小:
Windows組件是小:
在PX的寬度不改變,它改變僅密度:
小
DisplayMetrics{density=2.2250001, width=1080, height=1813, scaledDensity=2.2250001, xdpi=422.03, ydpi=424.069}
默認
DisplayMetrics{density=2.625, width=1080, height=1794, scaledDensity=2.625, xdpi=422.03, ydpi=424.069}
大
DisplayMetrics{density=2.875, width=1080, height=1782, scaledDensity=2.875, xdpi=422.03, ydpi=424.069}
較大
DisplayMetrics{density=3.125, width=1080, height=1770, scaledDensity=3.125, xdpi=422.03, ydpi=424.069}
最大
DisplayMetrics{density=3.375, width=1080, height=1758, scaledDensity=3.375, xdpi=422.03, ydpi=424.069}
可能是這樣的解決方案嗎? 'int smartphoneComponentWidth =((smartphoneDisplayWidth * scaledDensity)/ serverDisplayWidth)* serverComponentWidth;' – Giovesoft
放大Android N的能力超出了應用程序的範圍。另外,如果你在你的應用程序功能中只包含一個Android N,你就會限制很多可能的客戶端。 –