標籤:
擷取座標與座標點擊
一、座標相關的知識:
1)手機螢幕座標:左上方開始到右下角結束
2)DP:裝置獨立像素,例如320像素顯示到640像素上要展開一倍
3)Point:代表一個點(x,y),左上方的座標永遠為(0,0)
二、座標相關API:
| 傳回值 |
方法名 |
描述 |
| boolean |
click(int x, int y) |
使用座標點擊螢幕 |
| int |
getDisplayHeight() |
擷取螢幕高度 |
| Point |
getDisplaySizeDP() |
擷取顯示尺寸返回顯示大小(裝置獨立像素) 旋轉螢幕返回的顯示大小調整 |
| int |
getDisplayWidth() |
擷取螢幕寬度 |
三、UiAutomator Viewer擷取螢幕快照
進入android SDK的tools目錄下找到uiautomatorviewer.bat,雙擊開啟這個工具,就可以使用了
四、API使用舉例:
package com.uiautomatortest;import android.graphics.Point;import android.os.Bundle;import android.os.RemoteException;import android.view.KeyEvent;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class Test extends UiAutomatorTestCase { public void testClick(){ //get the display height and width int h=UiDevice.getInstance().getDisplayHeight(); int w=UiDevice.getInstance().getDisplayWidth(); Point p=UiDevice.getInstance().getDisplaySizeDp(); System.out.println("The display width is: "+w); System.out.println("The display height is: "+h); System.out.println(p); //click the clock UiDevice.getInstance().click(159,223); }}Test.java
Android無線測試之—UiAutomator UiDevice API介紹三