W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
我們在開發(fā)移動端應(yīng)用時(shí),首先會面臨一個很棘手的問題,就是市場上的手機(jī),平板等設(shè)備的屏幕尺寸、分辨率各有不同,屏寬比也多種多樣,如何來解決這個問題呢?
想要解決這個問題,我們需要了解一下關(guān)于顯示的一些基礎(chǔ)概念,已經(jīng)市場上我們常見的尺寸及分辨率。
常見的分辨率
1136*640,1920*1080,960*640,1280*720,800*480。
常見的屏幕尺寸
3.5英寸、4英寸、5英寸、5.5英寸、7英寸等等。
PX:pixels,就是絕對像素。大小固定,不會隨著屏幕不同而改變
PPI:Pixels Per Inch所表示的是每英寸所擁有的像素(Pixel)數(shù)目。因此PPI數(shù)值越高,即代表顯示屏能夠以越高的密度顯示圖像。當(dāng)然,顯示的密度越高,擬真度就越高。
DPI:每英寸所包含的點(diǎn),在Android設(shè)備上,通常以DPI來表示設(shè)備屏幕的顯示精細(xì)度。通常情況下,PPI和DPI可以表示同一個概念,PPI主要針對顯示設(shè)備,DPI更多應(yīng)用于打印輸出設(shè)備,但都表示每英寸所包含的像素點(diǎn)
打開ios目錄下RootViewController.mm文件
// Override to allow orientations other than the default portrait orientation.
// This method is deprecated on ios6
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
//豎屏
//return UIInterfaceOrientationIsPortrait( interfaceOrientation );
//橫屏
//return UIInterfaceOrientationIsLandscape( interfaceOrientation );
}
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
- (NSUInteger) supportedInterfaceOrientations{
#ifdef __IPHONE_6_0
//豎屏
//return UIInterfaceOrientationMaskPortrait;
//橫屏
//return UIInterfaceOrientationMaskLandscapeRight;
#endif
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//豎屏
//return UIInterfaceOrientationPortrait;
//橫屏
//return UIInterfaceOrientationLandscapeRight;
更改Device Orientation 屬性為Landscape Right 如圖:
AndroidManifest.xml中 activity 找到 android:screenOrientation屬性。
"unspecified":默認(rèn)值 由系統(tǒng)來判斷顯示方向.判定的策略是和設(shè)備相關(guān)的,所以不同的設(shè)備會有不同的顯示方向.
"landscape":橫屏顯示(寬比高要長)
"portrait":豎屏顯示(高比寬要長)
"user":用戶當(dāng)前首選的方向
"behind":和該Activity下面的那個Activity的方向一致(在Activity堆棧中的)
"sensor":有物理的感應(yīng)器來決定。如果用戶旋轉(zhuǎn)設(shè)備這屏幕會橫豎屏切換。
"nosensor":忽略物理感應(yīng)器,這樣就不會隨著用戶旋轉(zhuǎn)設(shè)備而更改了("unspecified"設(shè)置除外)。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: