自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Android屏幕大小相關(guān)技巧應(yīng)用指南

移動(dòng)開發(fā) Android
Android屏幕大小的改變方法多種多樣,可以根據(jù)用戶不同的需求來進(jìn)行更改。我們?cè)谶@篇文章中介紹的就是其中一個(gè)自適應(yīng)更改的方法。

Android應(yīng)用程序中屏幕大小的設(shè)置大家應(yīng)該都比較清楚,不過如何才能讓屏幕自己適應(yīng)環(huán)境而改變大小呢?在這里我們就可以為大家詳細(xì)介紹一下有關(guān)Android屏幕大小的自適應(yīng)方式,幫助大家理解。

不同的Android target會(huì)有不同的大小,應(yīng)用程序的界面需要針對(duì)不同的大小調(diào)整界面元素的尺寸。而且Android屏幕大小也可以在橫屏和豎屏之間切換,界面也需要調(diào)整。

如何取得屏幕的方向:

默認(rèn)情況下,當(dāng)屏幕方面切換時(shí),activity的onCreate()方法會(huì)被重新調(diào)用,所以可以在其中通過以下代碼來讀取屏的方向:

  1. view plaincopy to clipboardprint?  
  2. public void onCreate() {   
  3. if(this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_LANDSCAPE) {   
  4. Log.i("info", "landscape");   
  5. } else if (this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_PORTRAIT) {   
  6. Log.i("info", "portrait");   
  7. }   
  8. }   
  9. public void onCreate() {  
  10. if(this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_LANDSCAPE) {  
  11. Log.i("info", "landscape");  
  12. } else if (this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_PORTRAIT) {  
  13. Log.i("info", "portrait");  
  14. }  

如果在androidmanifest.xml中加入配置

  1. android:configChanges="orientation|keyboardHidden|navigation 

當(dāng)屏幕翻轉(zhuǎn)時(shí),Activity就不會(huì)重復(fù)的調(diào)用onCreate()、onPause()和onResume().

而是調(diào)用onConfigurationChanged(Configuration newConfig)

如何取得Android屏幕大?。?/p>

  1. view plaincopy to clipboardprint?  
  2. int screenWidth,screenHeight;   
  3. WindowManager windowManager = getWindowManager();   
  4. Display display = windowManager.getDefaultDisplay();   
  5. screenWidth = display.getWidth();   
  6. screenHeight = display.getHeight();   
  7. int screenWidth,screenHeight;  
  8. WindowManager windowManager = getWindowManager();  
  9. Display display = windowManager.getDefaultDisplay();  
  10. screenWidth = display.getWidth();  
  11. screenHeight = display.getHeight();  

也有人提到另一種Android屏幕大小的更改方法:

  1. view plaincopy to clipboardprint?  
  2. DisplayMetrics dm = new DisplayMetrics();   
  3. getWindowManager().getDefaultDisplay().getMetrics(dm);   
  4. int screenWidth = dm.widthPixels;   
  5. int screenHeight = dm.heightPixels;  

【編輯推薦】

  1. Android多媒體錄制功能的實(shí)現(xiàn)方式介紹
  2. Android圖片大小調(diào)整動(dòng)態(tài)實(shí)現(xiàn)方法
  3. Android界面互調(diào)具體應(yīng)用方式解析
  4. Android智能指針使用方法介紹
  5. Android查詢聯(lián)系人信息正確操作方法
責(zé)任編輯:曹凱 來源: CSDN
相關(guān)推薦

2010-01-25 13:50:41

Android輸出Lo

2010-01-28 10:55:14

Android電源管理

2010-01-25 18:27:54

Android進(jìn)度條

2009-12-29 16:08:41

Silverlight

2009-12-30 18:18:32

Silverlight

2010-01-26 18:00:07

Android屏幕元素

2009-12-28 15:01:39

WPF樹應(yīng)用

2009-12-31 16:44:53

Silverlight

2010-01-25 18:33:35

Android鍵盤操作

2010-01-25 18:22:33

Android使用XM

2009-12-30 10:25:03

Silverlight

2009-12-31 10:21:53

Silverlight

2010-01-28 11:26:39

Android log

2010-01-27 17:45:15

Android應(yīng)用技巧

2009-12-21 18:10:50

WCF實(shí)現(xiàn)事件通知

2009-12-30 09:55:51

Silverlight

2010-01-28 14:12:20

Android Act

2010-03-04 14:39:52

Python讀取輸入值

2010-02-05 13:44:06

C++ eof()函數(shù)

2010-01-25 17:43:13

Android資源
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)