简体   繁体   English

方向更改事件或监听器Android

[英]Orientation Changed Event or Listener Android

Is there any event or listener which fires @ time of orientation changed? 是否有任何事件或听众在@方向改变时发生了?

or, how to find out that the orientation of phone is changed? 或者,如何发现手机的方向改变了?

Thank You 谢谢

As far as I know there is a listener for this, 据我所知,有一个听众,

Check out http://developer.android.com/reference/android/view/OrientationListener.html 查看http://developer.android.com/reference/android/view/OrientationListener.html

That is the class have a look through there. 那是班级通过那里看看。

Hope that helped. 希望有所帮助。

You need to read up on Handling Runtime Changes . 您需要阅读有关处理运行时更改的信息

It explains the old way of doing handling stuff like orientation change. 它解释了处理方向改变之类的旧方法。

Since Fragments was introduced, they have implemented a new way of doing it (similar to the old one) - but if you don't use Fragments it makes no sense using it. 自从Fragments被引入以来,它们已经实现了一种新的方式(类似于旧的) - 但是如果你不使用Fragments ,使用它就没有意义了。

If you are more interested in when an orientation change triggers a redisplay of the layout, you might want to check out this: http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html 如果您对方向更改触发布局的重新显示更感兴趣,您可能需要查看以下内容: http//developer.android.com/reference/android/view/View.OnLayoutChangeListener.html

"Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing." “当视图的布局边界因布局处理而发生变化时,将调用回调的接口定义。”

Since 180° rotation are not detected by onConfigurationChanged, 由于onConfigurationChanged未检测到180°旋转,

See better answer here: How do I detect screen rotation 请在此处查看更好的答案: 如何检测屏幕旋转

On some phones orentation change event fires before actual resize event. 在某些手机上,orentation change事件会在实际调整大小之前触发。 Do not recommend u to use orientation change event when u need to know when form is resized. 当您需要知道何时调整表单大小时,不建议您使用方向更改事件。

Just use $(window).resize(function(){ stuff to do }) 只需使用$(window).resize(function(){stuff to do})

If u need to have dynamic resize event and change it at some point u can use structure like that 如果您需要动态调整大小事件并在某些时候更改它,您可以使用这样的结构

function ResizeEventHandler (){
  var resizeEvent = function(){}

  this.ResizeEvent = function(value){
        if (value!=null) resizeEvent = value;               
        else return resizeEvent()
  }
}

var ResizeEventHandlerInstance = new ResizeEventHandler();

$(window).resize(function(){ ResizeEventHandlerInstance.ResizeEvent();   });

function YourDinamicalEventSetterFunction(){
    ResizeEventHandlerInstance.ResizeEvent(function(){
               alert('resized');
    });
}

basically when u need to change resize event -> change ResizeEventHandlerInstance... and you will not need to unbind event all the time when u want to change it 基本上当你需要更改resize事件时 - >更改ResizeEventHandlerInstance ...并且当你想要改变它时你不需要一直取消绑定事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM