RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Android中如何设置屏幕大小-创新互联

这篇文章主要讲解了“Android中如何设置屏幕大小”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Android中如何设置屏幕大小”吧!

目前累计服务客户上1000家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都做网站、成都网站建设、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。成都创新互联公司始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。

默认情况下,当屏幕方面切换时,activity的onCreate()方法会被重新调用,所以可以在其中通过以下代码来读取屏的方向:

  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. public void onCreate() {

  8. if(this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_LANDSCAPE) {

  9. Log.i("info", "landscape");

  10. } else if (this.getResources().getConfiguration()
    .orientation == Configuration.ORIENTATION_PORTRAIT) {

  11. Log.i("info", "portrait");

  12. }

  13. }

如果在androidmanifest.xml中加入配置

android:configChanges="orientation|keyboardHidden|navigation

当屏幕翻转时,Activity就不会重复的调用onCreate()、onPause()和onResume().

而是调用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中如何设置屏幕大小”的内容了,经过本文的学习后,相信大家对Android中如何设置屏幕大小这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联网站建设公司,,小编将为大家推送更多相关知识点的文章,欢迎关注!


文章标题:Android中如何设置屏幕大小-创新互联
网页地址:http://sczitong.cn/article/djiegh.html