【问题标题】:Testing an Android device resolution using Robotium使用 Robotium 测试 Android 设备分辨率
【发布时间】:2013-01-07 10:46:41
【问题描述】:

有什么方法可以测试安卓设备的分辨率吗?

【问题讨论】:

  • “测试”分辨率是什么意思?我的意思是您可以随时使用任何标准方法来检索该信息。
  • 比如我想测试一下分辨率是不是400*400。

标签: android device junit4 resolution robotium


【解决方案1】:

在任何测试函数中,您都可以编写以下代码:

    Activity ACT = getActivity();


    Display display = ACT.getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    int height = size.y;

或者如果 API

Display display = getWindowManager().getDefaultDisplay(); 
int width = display.getWidth(); 
int height = display.getHeight(); 

【讨论】:

    【解决方案2】:

    希望得到帮助:[如果您打算为手机/平板电脑运行相同的测试代码]

    Configuration mConfig = mContext.getResources().getConfiguration();
    
    // checking for XLarge screen ...U can also check for Large screen similarly    
    if ((mConfig.screenLayout & Configuration.SCREENLAYOUT_SIZE_XLARGE) == Configuration.SCREENLAYOUT_SIZE_XLARGE) {  
    
            Log.i("TABLET MODE");
            // Do ur actions for Tablet
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多