开发者

Getting orientation of the device?

I have a camera preview activity, which is forced to stay in landsca开发者_如何学JAVApe mode.

Is there a way I can tell the current orientation of the phone (not the screen orientation).

Basically I want to know if the user is holding the phone in portrait mode, or in landscape mode, so I can rotate the output captured bitmap correctly (right now it just always outputs in landscape mode).

Thanks


if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
        {   
            p.set("orientation", "portrait");

            ....
        }
        if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
        {   
            p.set("orientation", "landscape");
            ....
        } 


You can also implement Application.onConfigurationChanged() to respond to orientation changes without having to register a SensorEventListener. It might be an easier way to go if you want to customize the layout depending on the phone orientation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜