安卓:监听取向的变化? [英] Android: listen for Orientation change?

查看:119
本文介绍了安卓:监听取向的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何会听的方向变化,Android的?和做某些事情的时候用户切换到风景?

How would I listen for orientation change in Android? and do certain things when the user has switched to landscape?

推荐答案

您有几个选择:

  • 使用的<一个href="http://developer.android.com/reference/android/view/OrientationEventListener.html">OrientationEventListener,其中有一个称为方法<一href="http://developer.android.com/reference/android/view/OrientationEventListener.html#onOrientationChanged(int)">onOrientationChanged.

  • Use an OrientationEventListener, which has a method called onOrientationChanged.

使用配置的变化:

在你的清单,把:

<activity android:name=".HelloAndroid"
    android:label="@string/app_name"
    android:configChanges="orientation">

和,在code,覆盖onConfigurationChanged

And, in code, override onConfigurationChanged

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    setContentView(R.layout.main);      
    // TODO
}

下面是一个很好的<一个href="http://jnastase.alner.net/archive/2010/10/27/handling-orientation-change-in-android.aspx">tutorial一下吧。

Here is a good tutorial about it.

这篇关于安卓:监听取向的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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