Android 方向改变事件或监听器

发布于 12-21 06:30 字数 63 浏览 4 评论 0原文

是否有任何事件或侦听器在方向改变时触发?

或者, 如何发现手机方向改变了?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

清风不识月2024-12-28 06:30:48

您需要阅读处理运行时更改

它解释了处理方向改变等问题的旧方法。

自从引入 Fragments 以来,他们实现了一种新的方法(与旧的类似) - 但如果您不使用 Fragments ,那么使用它就没有意义。

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.

节枝2024-12-28 06:30:48

据我所知,有一个侦听器,

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

这是一个类,可以在那里查看。

希望有帮助。

As far as I know there is a listener for this,

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

That is the class have a look through there.

Hope that helped.

绝不服输2024-12-28 06:30:48

如果您对方向更改何时触发布局重新显示更感兴趣,您可能需要查看以下内容:http://developer.android.com/reference/android/view/View.OnLayoutChangeListener.html

"视图布局边界更改时调用的回调的接口定义由于布局处理。”

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

"Interface definition for a callback to be invoked when the layout bounds of a view changes due to layout processing."

窝囊感情。2024-12-28 06:30:48

由于 onConfigurationChanged 未检测到 180° 旋转,

请在此处查看更好的答案:
如何检测屏幕旋转

Since 180° rotation are not detected by onConfigurationChanged,

See better answer here:
How do I detect screen rotation

魄砕の薆2024-12-28 06:30:48

在某些手机上,方向更改事件会在实际调整大小事件之前触发。当您需要知道表单何时调整大小时,不建议您使用方向更改事件。

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

如果您需要动态调整大小事件并在某个时刻更改它,那么

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');
    });
}

基本上当您需要更改调整大小事件时,您可以使用类似的结构 ->更改 ResizeEventHandlerInstance...并且当您想要更改它时,您将不需要一直取消绑定事件

On some phones orentation change event fires before actual resize event. 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 })

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文