我可以在 Android 中检测两种风景吗?
旋转设备时是否可以检测一种横向与另一种横向?
@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();
}
}
有效,但我想看看是否可以确定它位于手机的哪一侧,因为我想显示不同的布局。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于运行 Android 2.2+ 的设备,您可以。请查看这篇博文了解详细信息,或者您可以跳到重点。
You can, for devices running Android 2.2+. Check out this blog post for the details or you can skip to the punchline.