標籤:
滑動地區校準常量設定與擷取
一、校準概念
校準常量指的是:滑動操作座標時的位移量,用來取位移比例
二、相關API
| 傳回值 |
API |
描述 |
| double |
getSwipeDeadZonePercentage() |
擷取無接觸區百分比的值,預設常量值為0.1,即10% |
| UiScrollable |
setSwipeDeadZonePercentage(double swipeDeadZonePercentage) |
設定一個組件的大小,在滑動時,視為無接觸區的百分比。 |
三、API應用舉例
package com.testuiselector;import com.android.uiautomator.core.UiDevice;import com.android.uiautomator.core.UiObject;import com.android.uiautomator.core.UiObjectNotFoundException;import com.android.uiautomator.core.UiScrollable;import com.android.uiautomator.core.UiSelector;import com.android.uiautomator.testrunner.UiAutomatorTestCase;public class Demo extends UiAutomatorTestCase { /** * @param args */ public static void main(String[] args) { String jarName, testClass, testName, androidId; jarName="demo2"; testClass="com.testuiselector.Demo"; testName="testSwipeDeadZonePercentage"; androidId="1"; new UiAutomatorHelper(jarName, testClass, testName, androidId); } public void testSwipeDeadZonePercentage() throws UiObjectNotFoundException{ UiDevice.getInstance().pressHome(); sleep(1000); UiObject people=new UiObject(new UiSelector().text("People")); people.clickAndWaitForNewWindow(); UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView")); scroll.flingForward(); System.out.println("滑動時,無接觸區百分比: "+scroll.getSwipeDeadZonePercentage()); //滑動時,無接觸地區百分比設定為50%時,基本沒有滑動,因此這個滑動操作成了一個一點擊操作 scroll.setSwipeDeadZonePercentage(0.5); scroll.flingForward(); System.out.println("滑動時,無接觸區百分比: "+scroll.getSwipeDeadZonePercentage()); }}Demo.java
Android無線測試之—UiAutomator UiScrollable API介紹五