我怎样才能检测纵向模式在android系统取向的变化? [英] How can i detect orientation changes in portrait mode in android?

查看:167
本文介绍了我怎样才能检测纵向模式在android系统取向的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的应用程序,以显示一个照相机preVIEW使得照片可以通过按下按钮作出。
所以,我把pretty标准相机preVIEW类。问题是我必须把它在横向模式下,使得preVIEW可以在整个屏幕上伸展。如果在纵向模式下,它将保持仅在屏幕的中心,在它的一小部分。如果这可以解决容易,我很开放的建议。

I need to show a camera preview in my app so that the photos can be taken by pushing a button. So I put a pretty "standard" camera preview class. The problem is I have to put it in landscape mode so that the preview can stretch on the entire screen. If in portrait mode, it will remain only on the center of the screen, on a small part of it. If this can be solved easier, I am open to suggestions.

但我的问题是。如果锁定在横向模式下,如何检测屏幕旋转,这样我可以相应地旋转按钮的文字?
我试过

But my question is. If locked in landscape mode, how can i detect screen rotation so that i can rotate text of the button accordingly ? I tried

@Override
public void onSensorChanged(SensorEvent event)
{
    Log.d("onSensorChanged");
    Log.d("event:" + event);

}

但我得到任何结果。

but I get no result.

推荐答案

使用OrientationEventListener

orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_UI) {
    public void onOrientationChanged(int orientation) {
        //do something
    }
};

这篇关于我怎样才能检测纵向模式在android系统取向的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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