编程使用按钮更改屏幕显示方向 [英] Change Screen Orientation programatically using a Button
问题描述
我觉得这是可实现的,因为屏幕旋转行为上升到了应用层面。有没有例子可用?我试图寻找,但发现很少有这一点。
I think this is implementable since screen rotation behaviour can go up to the application level. Is there any example available ? I tried to search but found very few of this.
推荐答案
是的,它是可实现的!
<一个href="http://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_LANDSCAPE">ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
<一个href="http://developer.android.com/reference/android/content/pm/ActivityInfo.html#SCREEN_ORIENTATION_PORTRAIT">ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
ActivityInfo
<一个href="http://developer.android.com/reference/android/content/pm/ActivityInfo.html">http://developer.android.com/reference/android/content/pm/ActivityInfo.html
介 链接:
Button buttonSetPortrait = (Button)findViewById(R.id.setPortrait);
Button buttonSetLandscape = (Button)findViewById(R.id.setLandscape);
buttonSetPortrait.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
});
buttonSetLandscape.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
});
<一个href="http://android-er.blogspot.in/2011/08/set-screen-orientation-programmatically.html">http://android-er.blogspot.in/2011/08/set-screen-orientation-programmatically.html
这篇关于编程使用按钮更改屏幕显示方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!