在 ANDROID 程序中禁止屏幕旋转

android中每次屏幕方向切换时都会重启Activity,要避免在转屏时重启Activity,可以通过在AndroidManifest.xml文件中重新定义方向(给每个Activity加上 android:configChanges=”keyboardHidden|orientation” 属性)。
在需要控制屏幕显示方向的Activity中重写onConfigurationChanged(Configuration newConfig)方法,这样在转屏时就不会重启Activity了。

if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
  1.   //横向
  2.   setContentView(R.layout.file_list_landscape);
  3. }else{
  4.   //竖向
  5.    setContentView(R.layout.file_list);
  6. }

在模拟器中可以按 CTL+F11 模拟做屏幕旋转

有时候我们希望让一个程序的界面始终保持在一个方向,不随手机方向旋转而变化
在AndroidManifest.xml的每一个需要禁止转向的Activity配置中加入android:screenOrientation=”landscape” 属性。

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: