支持横竖屏幕的切换代码如下:

public class TestActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); LinearLayout layout=(LinearLayout)findViewById(R.id.test_linearlayout); AutoBackground(this,layout,R.drawable.portrait,R.drawable.landscape); } 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); } } }

更多相关文章

  1. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Fedora镜像
  2. 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
  3. Android(安卓)Activity界面切换添加动画特效
  4. android EditText设置不可写
  5. Android屏幕分辨率正确获取及PX,DPI,DP,SP等的对应关系
  6. Android系统配置数据库注释(settings.db)
  7. Android(安卓)Activity的启动
  8. android 分辨率及密度详细
  9. Android屏幕常亮

随机推荐

  1. redis
  2. 欧洲顶级银行 BBVA,区块链与 DevOps 的先
  3. 14:VMware Horizon View 8.0-创建完整克隆
  4. 【必读】2021年DevOps工程师学习路径
  5. 2021年DevOps工程师需要掌握哪些技能才可
  6. JMeter如何使用MD5加密并且对body进行指
  7. 话说 类加载过程 第二篇
  8. Cloudam云端,探索高性能计算在药物研究领
  9. 互联网测试校招系列1:赢在测试岗位
  10. K8S v1.18.x 部署-Kubeadm方式-4:部署负载