Can I detect both landscapes in android? [duplicate]

守給你的承諾、 提交于 2019-12-13 01:48:25

问题


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.onConfigurationChanged(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.


回答1:


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



来源:https://stackoverflow.com/questions/6020463/can-i-detect-both-landscapes-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!