Can I detect both landscapes in android? [duplicate]
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.
精彩评论