Android横竖屏检测

2014-11-24 03:24:53 · 作者: · 浏览: 2


检测横竖屏:
重写函数:
@Override
public void onConfigurationChanged(Configuration config) {
try {
super.onConfigurationChanged(config);
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {

Toast.makeText(TestApp2.this, "当前是横向",Toast.LENGTH_SHORT).show();
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
Toast.makeText(TestApp2.this, "哈哈,切竖屏",Toast.LENGTH_SHORT).show();
}
} catch (Exception ex) {
}
}