在更改屏幕方向Android中需要帮助 [英] Need Help in Changing Screen Orientation in Android

查看:78
本文介绍了在更改屏幕方向Android中需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变屏幕方向从纵向到横向,反之亦然当用户旋转他的Andr​​oid手机顺时针/逆时针。谁能帮助我如何实现这一目标?我不知道是什么事件被激发,当用户旋转他的Andr​​oid手机。

I want to change the screen orientation from portrait to landscape and vice versa when the user rotates his Android mobile phone clockwise/anticlockwise. Can anyone help me how to achieve this? I do not know what event is fired when the user rotates his Android mobile phone.

有关例如,当用户触摸在UI上按钮,触摸事件。因此,当用户摇摇Android手机,什么是触发事件?请帮我在这。

For instance, when the user touches the button in UI, touch event is fired. So, when the user shakes his Android mobile phone, what is the event that is fired? Please help me on this.

推荐答案

海,      我得到了解决方案的帮助下格奥尔基Gobozov ,但该解决方案已被细化,如下图所示,以正常工作了,

Hai, I got Solution with the help of Georgy Gobozov, But that solution has to be refined as shown below to work it properly,

@Override
    public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);

     if(newConfig.equals(Configuration.ORIENTATION_LANDSCAPE))
     {
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);  
     }
     else if(newConfig.equals(Configuration.ORIENTATION_PORTRAIT))
     {
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
     }
    } 

这篇关于在更改屏幕方向Android中需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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