public class testScreenRotation extends Activity {
/** Called when the activity is first created. */
private int mRuntimeOrientation;
private boolean mDisableScreenRotation=true;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRuntimeOrientation = this.getScreenOrientation();
setContentView(R.layout.main);
}
protected int getScreenOrientation() {
/*
Display display = getWindowManager().getDefaultDisplay();
int orientation = display.getOrientation();
if (orientation == Configuration.ORIENTATION_UNDEFINED) {
orientation = getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_UNDEFINED) {
if (display.getWidth() == display.getHeight())
orientation = Configuration.ORIENTATION_SQUARE;
else if(display.getWidth() < display.getHeight())
orientation = Configuration.ORIENTATION_PORTRAIT;
else
orientation = Configuration.ORIENTATION_LANDSCAPE;
}
}
return orientation;
*/
return Configuration.ORIENTATION_PORTRAIT;
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
if (mDisableScreenRotation) {
super.onConfigurationChanged(newConfig);
this.setRequestedOrientation(mRuntimeOrientation);
} else {
mRuntimeOrientation = this.getScreenOrientation();
super.onConfigurationChanged(newConfig);
}
}
}
我的应用程序,并添加机器人:在xml.when configChanges =“方向”我的应用程序开始我的屏幕是人像,我按下CTRL + F12,屏幕也roate ,屏幕是LANDSCAPE,第二我按Ctrl + F12,屏幕也旋转,屏幕是PORTRAIT,然后我按下Ctrl + F12,屏幕保持PORTRAIT。所以我再次按下,屏幕保持PORTRAIT。我的问题是,为什么我的屏幕在应用程序启动时不保持PORTRAIT。禁用屏幕旋转在Android如上
编辑:我想用代码来控制屏幕旋转,如果我能做到这一点?
感谢您answer.i还我可以用代码来保持屏幕肖像 – pengwang 2011-04-06 09:54:49
@pengwang它是否解决问题了吗?如果是这样,请接受它作为答案。 – pecka85 2011-04-11 08:48:54
不,我找不到方法 – pengwang 2011-04-11 09:32:53