编程使用按钮更改屏幕显示方向 [英] Change Screen Orientation programatically using a Button

查看:168
本文介绍了编程使用按钮更改屏幕显示方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这是可实现的,因为屏幕旋转行为上升到了应用层面。有没有例子可用?我试图寻找,但发现很少有这一点。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆