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;
}
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;
}
相关文章推荐
- 队列
- Lambda 表达式的示例-来源(MSDN)
- WebSphere安装、系统部署、连接池
- Nginx/tengine里的那些timeout时间
- 常用SQL查询语句
- zabbix监控nginx连接状态(转)
- Hdoj-1563-Find your present!
- kafka创建topic报错:KeeperException$NoNodeException: KeeperErrorCode = NoNode for /brokers/ids
- java导出Excel通用方法
- Android数据库 SQLite数据库
- Median of Two Sorted Arrays
- HDU 3629-Convex找凸四边形个数(扫描+二分/two pointers)
- 常见jquery函数集合总结
- 唯品会——java开发实习生机试
- 几种最常见的网站盈利模式分析
- Delphi 实现Ini文件参数与TEdit和TCheckBox绑定(TSimpleParam)
- android数据存储——文件存储
- parcelable接口
- 剑指offer-面试题37.两个链表的第一个公共结点
- 原生js和jquery实现图片轮播特效