這篇文章主要講解了“Android中如何設(shè)置屏幕大小”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“Android中如何設(shè)置屏幕大小”吧!
目前累計(jì)服務(wù)客戶上1000家,積累了豐富的產(chǎn)品開發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹立企業(yè)形象,為客戶提供成都做網(wǎng)站、成都網(wǎng)站建設(shè)、網(wǎng)站策劃、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。成都創(chuàng)新互聯(lián)公司始終以務(wù)實(shí)、誠(chéng)信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過對(duì)領(lǐng)先技術(shù)的掌握、對(duì)創(chuàng)意設(shè)計(jì)的研究、對(duì)客戶形象的視覺傳遞、對(duì)應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。默認(rèn)情況下,當(dāng)屏幕方面切換時(shí),activity的onCreate()方法會(huì)被重新調(diào)用,所以可以在其中通過以下代碼來(lái)讀取屏的方向:
view plaincopy to clipboardprint?
public void onCreate() {
if(this.getResources().getConfiguration()
.orientation == Configuration.ORIENTATION_LANDSCAPE) {Log.i("info", "landscape");
} else if (this.getResources().getConfiguration()
.orientation == Configuration.ORIENTATION_PORTRAIT) {Log.i("info", "portrait");
}
}
public void onCreate() {
if(this.getResources().getConfiguration()
.orientation == Configuration.ORIENTATION_LANDSCAPE) {Log.i("info", "landscape");
} else if (this.getResources().getConfiguration()
.orientation == Configuration.ORIENTATION_PORTRAIT) {Log.i("info", "portrait");
}
}
如果在androidmanifest.xml中加入配置
android:configChanges="orientation|keyboardHidden|navigation
當(dāng)屏幕翻轉(zhuǎn)時(shí),Activity就不會(huì)重復(fù)的調(diào)用onCreate()、onPause()和onResume().
而是調(diào)用onConfigurationChanged(Configuration newConfig)
如何取得Android屏幕大小:
view plaincopy to clipboardprint? int screenWidth,screenHeight; WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight(); int screenWidth,screenHeight; WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();
也有人提到另一種Android屏幕大小的更改方法:
view plaincopy to clipboardprint? DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); int screenWidth = dm.widthPixels; int screenHeight = dm.heightPixels;
感謝各位的閱讀,以上就是“Android中如何設(shè)置屏幕大小”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)Android中如何設(shè)置屏幕大小這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián)網(wǎng)站建設(shè)公司,,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!