您的位置:首页 > 其它

Activity区分平板和手机加载布局文件

2016-04-08 13:07 330 查看
if (isTabletDevice()) {
setContentView(R.layout.title_activity_ft_bt_demo);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

// setContentView(R.layout.activity_phone);
} else {
setContentView(R.layout.activity_phone);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

private boolean isTabletDevice() {
if (android.os.Build.VERSION.SDK_INT >= 11) { // honeycomb
// test screen size, use reflection because isLayoutSizeAtLeast is
// only available since 11
Configuration con = getResources().getConfiguration();
try {
Method mIsLayoutSizeAtLeast = con.getClass().getMethod(
"isLayoutSizeAtLeast", int.class);
Boolean r = (Boolean) mIsLayoutSizeAtLeast.invoke(con,
0x00000004); // Configuration.SCREENLAYOUT_SIZE_XLARGE
return r;
} catch (Exception x) {
x.printStackTrace();
return false;
}
}
return false;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: