android中判断横屏或者竖屏并改变背景
来源:互联网 发布:物理其实很简单. 淘宝 编辑:程序博客网 时间:2024/04/29 16:49
在android中,判断横屏还是竖屏,并且根据方向改变背景,代码如下:
public static int ScreenOrient(Activity activity) { int orient = activity.getRequestedOrientation(); if(orient != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE && orient != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { //寬>高爲橫屏,反正爲豎屏 WindowManager windowManager = activity.getWindowManager(); Display display = windowManager.getDefaultDisplay(); int screenWidth = display.getWidth(); int screenHeight = display.getHeight(); orient = screenWidth < screenHeight ? ActivityInfo.SCREEN_ORIENTATION_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; } return orient; }
public static void AutoBackground(Activity activity,View view,int Background_v, int Background_h) { int orient=ScreenOrient(activity); if (orient == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { //纵向 view.setBackgroundResource(Background_v); }else{ //横向 view.setBackgroundResource(Background_h); } }
其中Background_v是纵向时的背景图,view.setBackgroundResource为横向时的背景图
然后在activity的oncreate方法中去调用
LinearLayout layout=(LinearLayout)findViewById(R.id.layout);
//背景自动适应
androidUtil.AutoBackground(this, layout, R.drawable.bg_v, R.drawable.bg_h);
- android中判断横屏或者竖屏并改变背景
- android中判断横屏或者竖屏并改变背景
- Android判断当前是横屏或者竖屏
- Android中改变Dialog背景透明度
- 如何判断ipad或者iphone是否为横屏或者竖屏 - portrait或者landsc
- android 界面 按button或者imagebutton改变图片或者背景的效果
- android progressBar 背景改变
- android 背景透明度改变
- [JS代码]如何判断ipad或者iphone是否为横屏或者竖屏 - portrait或者landscape
- ASP.NET--TreeView中被选中Node改变背景或者字体颜色。
- iOS 点击cell改变背景颜色或者图片&&cell中其他部分取消高亮显示
- Android中设置Button或者ImageButton的背景透明
- android中 关于listitem 获得焦点时,改变其背景
- android中 关于listitem 获得焦点时,改变其背景
- Android中Selsetor基本使用一,按下时改变按钮背景
- Android中使用Java代码动画改变背景颜色
- android中 关于listitem 获得焦点时,改变其背景
- Android中TabHost动态修改图标或者动态改变标题
- 从excal倒入到数据库
- Installing and setting TFTPD in Ubuntu
- gcc编译的背后(预处理、编译、汇编和链接) 一
- weblogic的使用
- 世界上顶级英文歌曲
- android中判断横屏或者竖屏并改变背景
- 《C++第十四周实验报告1-1》---建立专门的数组类处理有关数组的操作
- 火车的运气奇遇
- 编译libfetion时,提示 从 int 到 QString 的转换有歧义
- 配置Oracle本地Net服务名
- 《C++第十四周实验报告1-2》---规定MyArray只能处理元素为整型的数据未免太弱了, 请设计成模板类,使之适应各种类型
- Darren大话设计模式之依赖倒转原则
- s3c6410在linux下的WATCHDOG TIMER(看门狗定时器)驱动(3)
- Flex控件中的Graphics: CheckBox