开发者

Can I detect both landscapes in android? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

How to detect landscape left (normal) vs landscape right (reverse) with support for naturally landscape devices?

Is it possible to detect one landscape vs the other landscape when rotating the device?

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.o开发者_运维知识库nConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
    }
    else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
    {
        Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
    }
}

works but I'd like to see if I can determine which side of the phone it is on as I want to display a different layout.


You can, for devices running Android 2.2+. Check out this blog post for the details or you can skip to the punchline.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜