今天学到一招,在android中,判断横屏还是竖屏,并且根据方向改变背景,代码如下:
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);

更多相关文章

  1. android背景选择器selector用法汇总
  2. android中判断横屏或者竖屏并改变背景
  3. Android(安卓)activity属性设置大全
  4. Android中取消GridView & ListView默认的点击背景色
  5. Android开发:布局分区域设置不同背景色
  6. android Button 点击背景与文字颜色变化效果
  7. android中判断横屏或者竖屏并改变背景
  8. android中判断横屏或者竖屏并改变背景
  9. android 用 XML 自定义边框(只上下边框有色)

随机推荐

  1. android 结合 opencv项目(NDK、OpenCV、an
  2. Android消息机制和应用
  3. Android 面试必备 - JVM 及 类加载机制
  4. Android 5.0 API新增和改进
  5. Android Property System | Android属性
  6. Android腾讯微薄客户端开发教程汇总
  7. Android(安卓)通过NTP服务器自动获取时间
  8. ImageView---属性android:background与andro
  9. Android开发工具下载地址
  10. android(2)——Structure of an Android