Most visited

Recently visited

Added in API level 1
Deprecated since API level 24

TouchUtils

public class TouchUtils
extends Object

java.lang.Object
   ↳ android.test.TouchUtils


此类在API级别24中已被弃用。
改为使用Espresso UI testing framework 新的测试应该使用Android Testing Support Library编写

用于生成触摸事件的可重用方法。 这些方法可以与InstrumentationTestCase或ActivityInstrumentationTestCase2一起使用,通过触摸屏模拟用户与应用程序的交互。

Summary

Public constructors

TouchUtils()

Public methods

static void clickView(InstrumentationTestCase test, View v)

模拟触摸视图的中心并释放。

static void drag(InstrumentationTestCase test, float fromX, float toX, float fromY, float toY, int stepCount)

模拟触摸特定位置并拖动到新位置。

static void drag(ActivityInstrumentationTestCase test, float fromX, float toX, float fromY, float toY, int stepCount)

此方法在API级别被废弃3. ActivityInstrumentationTestCase赞成不赞成ActivityInstrumentationTestCase2 ,其用于测试配置活动提供更多的选择

static void dragQuarterScreenDown(InstrumentationTestCase test, Activity activity)

模拟屏幕中央的触摸并向下拖动四分之一处

static void dragQuarterScreenDown(ActivityInstrumentationTestCase test)

此方法在API级别被废弃3. ActivityInstrumentationTestCase赞成不赞成ActivityInstrumentationTestCase2 ,其用于测试配置活动提供更多的选择

static void dragQuarterScreenUp(ActivityInstrumentationTestCase test)

此方法在API级别3中已弃用ActivityInstrumentationTestCase已弃用,用于支持ActivityInstrumentationTestCase2 ,该选项为配置待测活动提供了更多选项

static void dragQuarterScreenUp(InstrumentationTestCase test, Activity activity)

模拟屏幕中心的触摸并向上拖动四分之一

static int dragViewBy(InstrumentationTestCase test, View v, int gravity, int deltaX, int deltaY)

此方法在API级别被废弃3. ActivityInstrumentationTestCase赞成不赞成ActivityInstrumentationTestCase2 ,其用于测试配置活动提供更多的选择

static int dragViewBy(ActivityInstrumentationTestCase test, View v, int gravity, int deltaX, int deltaY)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

static int dragViewTo(ActivityInstrumentationTestCase test, View v, int gravity, int toX, int toY)

此方法在API级别3中已弃用ActivityInstrumentationTestCase已弃用,而ActivityInstrumentationTestCase2提供了更多选项,用于配置待测活动

static int dragViewTo(InstrumentationTestCase test, View v, int gravity, int toX, int toY)

模拟触摸视图并将其拖动到指定位置。

static void dragViewToBottom(ActivityInstrumentationTestCase test, View v)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

static void dragViewToBottom(InstrumentationTestCase test, Activity activity, View v, int stepCount)

模拟触摸视图的中心并拖动到屏幕底部。

static void dragViewToBottom(ActivityInstrumentationTestCase test, View v, int stepCount)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

static void dragViewToBottom(InstrumentationTestCase test, Activity activity, View v)

模拟触摸视图的中心并拖动到屏幕底部。

static void dragViewToTop(InstrumentationTestCase test, View v)

模拟触摸视图的中心并拖动到屏幕顶部。

static void dragViewToTop(ActivityInstrumentationTestCase test, View v)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

static void dragViewToTop(InstrumentationTestCase test, View v, int stepCount)

模拟触摸视图的中心并拖动到屏幕顶部。

static void dragViewToTop(ActivityInstrumentationTestCase test, View v, int stepCount)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已弃用,而ActivityInstrumentationTestCase2ActivityInstrumentationTestCase2更多选项,用于配置待测活动

static int dragViewToX(InstrumentationTestCase test, View v, int gravity, int toX)

模拟触摸视图并将其拖动到指定位置。

static int dragViewToX(ActivityInstrumentationTestCase test, View v, int gravity, int toX)

此方法在API级别3中已弃用ActivityInstrumentationTestCase已弃用,而ActivityInstrumentationTestCase2提供了更多选项,用于配置待测活动

static int dragViewToY(ActivityInstrumentationTestCase test, View v, int gravity, int toY)

此方法在API级别3中已弃用ActivityInstrumentationTestCase已弃用,用于支持ActivityInstrumentationTestCase2 ,该选项为配置待测活动提供了更多选项

static int dragViewToY(InstrumentationTestCase test, View v, int gravity, int toY)

模拟触摸视图并将其拖动到指定位置。

static void longClickView(ActivityInstrumentationTestCase test, View v)

此方法在API级别3中已弃用ActivityInstrumentationTestCase已被弃用,而ActivityInstrumentationTestCase2已提供更多选项,用于配置被测活动

static void longClickView(InstrumentationTestCase test, View v)

模拟触摸视图的中心,持续到长按,然后释放。

static void scrollToBottom(ActivityInstrumentationTestCase test, ViewGroup v)

此方法在API级别被废弃3. ActivityInstrumentationTestCase赞成不赞成ActivityInstrumentationTestCase2 ,其用于测试配置活动提供更多的选择

static void scrollToBottom(InstrumentationTestCase test, Activity activity, ViewGroup v)

通过反复调用 dragQuarterScreenUp(InstrumentationTestCase, Activity)将ViewGroup滚动到底 dragQuarterScreenUp(InstrumentationTestCase, Activity)

static void scrollToTop(ActivityInstrumentationTestCase test, ViewGroup v)

此方法在API级别3中ActivityInstrumentationTestCase被弃用ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

static void scrollToTop(InstrumentationTestCase test, Activity activity, ViewGroup v)

通过反复呼叫 dragQuarterScreenDown(InstrumentationTestCase, Activity)将ViewGroup滚动到顶部

static void tapView(InstrumentationTestCase test, View v)

模拟触摸视图中心并快速释放(轻拍超时之前)。

static void touchAndCancelView(InstrumentationTestCase test, View v)

模拟触摸视图的中心并取消(所以没有onClick应该触发等)。

Inherited methods

From class java.lang.Object

Public constructors

TouchUtils

Added in API level 1
TouchUtils ()

Public methods

clickView

Added in API level 1
void clickView (InstrumentationTestCase test, 
                View v)

模拟触摸视图的中心并释放。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be clicked

drag

Added in API level 3
void drag (InstrumentationTestCase test, 
                float fromX, 
                float toX, 
                float fromY, 
                float toY, 
                int stepCount)

模拟触摸特定位置并拖动到新位置。

Parameters
test InstrumentationTestCase: The test case that is being run
fromX float: X coordinate of the initial touch, in screen coordinates
toX float: Xcoordinate of the drag destination, in screen coordinates
fromY float: X coordinate of the initial touch, in screen coordinates
toY float: Y coordinate of the drag destination, in screen coordinates
stepCount int: How many move steps to include in the drag

drag

Added in API level 1
void drag (ActivityInstrumentationTestCase test, 
                float fromX, 
                float toX, 
                float fromY, 
                float toY, 
                int stepCount)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸特定位置并拖动到新位置。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
fromX float: X coordinate of the initial touch, in screen coordinates
toX float: Xcoordinate of the drag destination, in screen coordinates
fromY float: X coordinate of the initial touch, in screen coordinates
toY float: Y coordinate of the drag destination, in screen coordinates
stepCount int: How many move steps to include in the drag

dragQuarterScreenDown

Added in API level 3
void dragQuarterScreenDown (InstrumentationTestCase test, 
                Activity activity)

模拟屏幕中央的触摸并向下拖动四分之一处

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case

dragQuarterScreenDown

Added in API level 1
void dragQuarterScreenDown (ActivityInstrumentationTestCase test)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,因此支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟屏幕中央的触摸并向下拖动四分之一处

Parameters
test ActivityInstrumentationTestCase: The test case that is being run

dragQuarterScreenUp

Added in API level 1
void dragQuarterScreenUp (ActivityInstrumentationTestCase test)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟屏幕中心的触摸并向上拖动四分之一

Parameters
test ActivityInstrumentationTestCase: The test case that is being run

dragQuarterScreenUp

Added in API level 3
void dragQuarterScreenUp (InstrumentationTestCase test, 
                Activity activity)

模拟屏幕中心的触摸并向上拖动四分之一

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case

dragViewBy

Added in API level 3
int dragViewBy (InstrumentationTestCase test, 
                View v, 
                int gravity, 
                int deltaX, 
                int deltaY)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,因此支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图并将其拖动指定量。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
deltaX int: Amount to drag horizontally in pixels
deltaY int: Amount to drag vertically in pixels
Returns
int distance in pixels covered by the drag

dragViewBy

Added in API level 1
int dragViewBy (ActivityInstrumentationTestCase test, 
                View v, 
                int gravity, 
                int deltaX, 
                int deltaY)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图并将其拖动指定量。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
deltaX int: Amount to drag horizontally in pixels
deltaY int: Amount to drag vertically in pixels
Returns
int distance in pixels covered by the drag

dragViewTo

Added in API level 1
int dragViewTo (ActivityInstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toX, 
                int toY)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图并将其拖动到指定位置。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX int: Final location of the view after dragging
toY int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

dragViewTo

Added in API level 3
int dragViewTo (InstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toX, 
                int toY)

模拟触摸视图并将其拖动到指定位置。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX int: Final location of the view after dragging
toY int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

dragViewToBottom

Added in API level 1
void dragViewToBottom (ActivityInstrumentationTestCase test, 
                View v)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase不赞成使用ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图的中心并拖动到屏幕底部。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged

dragViewToBottom

Added in API level 3
void dragViewToBottom (InstrumentationTestCase test, 
                Activity activity, 
                View v, 
                int stepCount)

模拟触摸视图的中心并拖动到屏幕底部。

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case
v View: The view that should be dragged
stepCount int: How many move steps to include in the drag

dragViewToBottom

Added in API level 1
void dragViewToBottom (ActivityInstrumentationTestCase test, 
                View v, 
                int stepCount)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图的中心并拖动到屏幕底部。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
stepCount int: How many move steps to include in the drag

dragViewToBottom

Added in API level 3
void dragViewToBottom (InstrumentationTestCase test, 
                Activity activity, 
                View v)

模拟触摸视图的中心并拖动到屏幕底部。

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case
v View: The view that should be dragged

dragViewToTop

Added in API level 3
void dragViewToTop (InstrumentationTestCase test, 
                View v)

模拟触摸视图的中心并拖动到屏幕顶部。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged

dragViewToTop

Added in API level 1
void dragViewToTop (ActivityInstrumentationTestCase test, 
                View v)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,因此支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

模拟触摸视图的中心并拖动到屏幕顶部。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged

dragViewToTop

Added in API level 3
void dragViewToTop (InstrumentationTestCase test, 
                View v, 
                int stepCount)

模拟触摸视图的中心并拖动到屏幕顶部。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
stepCount int: How many move steps to include in the drag

dragViewToTop

Added in API level 1
void dragViewToTop (ActivityInstrumentationTestCase test, 
                View v, 
                int stepCount)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

模拟触摸视图的中心并拖动到屏幕顶部。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
stepCount int: How many move steps to include in the drag

dragViewToX

Added in API level 3
int dragViewToX (InstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toX)

模拟触摸视图并将其拖动到指定位置。 只能水平移动。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

dragViewToX

Added in API level 1
int dragViewToX (ActivityInstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toX)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

模拟触摸视图并将其拖动到指定位置。 只能水平移动。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toX int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

dragViewToY

Added in API level 1
int dragViewToY (ActivityInstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toY)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

模拟触摸视图并将其拖动到指定位置。 只能垂直移动。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toY int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

dragViewToY

Added in API level 3
int dragViewToY (InstrumentationTestCase test, 
                View v, 
                int gravity, 
                int toY)

模拟触摸视图并将其拖动到指定位置。 只能垂直移动。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be dragged
gravity int: Which part of the view to use for the initial down event. A combination of (TOP, CENTER_VERTICAL, BOTTOM) and (LEFT, CENTER_HORIZONTAL, RIGHT)
toY int: Final location of the view after dragging
Returns
int distance in pixels covered by the drag

longClickView

Added in API level 1
void longClickView (ActivityInstrumentationTestCase test, 
                View v)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase弃用ActivityInstrumentationTestCase2 ,这为配置被测活动提供了更多选项

模拟触摸视图的中心,持续到长按,然后释放。

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v View: The view that should be clicked

longClickView

Added in API level 3
void longClickView (InstrumentationTestCase test, 
                View v)

模拟触摸视图的中心,持续到长按,然后释放。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be clicked

scrollToBottom

Added in API level 1
void scrollToBottom (ActivityInstrumentationTestCase test, 
                ViewGroup v)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,因此支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

通过反复调用 dragQuarterScreenUp(InstrumentationTestCase, Activity)将ViewGroup滚动到底 dragQuarterScreenUp(InstrumentationTestCase, Activity)

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v ViewGroup: The ViewGroup that should be dragged

scrollToBottom

Added in API level 3
void scrollToBottom (InstrumentationTestCase test, 
                Activity activity, 
                ViewGroup v)

通过反复调用 dragQuarterScreenUp(InstrumentationTestCase, Activity)将ViewGroup滚动到底 dragQuarterScreenUp(InstrumentationTestCase, Activity)

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case
v ViewGroup: The ViewGroup that should be dragged

scrollToTop

Added in API level 1
void scrollToTop (ActivityInstrumentationTestCase test, 
                ViewGroup v)

此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项

通过反复调用 dragQuarterScreenDown(InstrumentationTestCase, Activity)将ViewGroup滚动到顶部

Parameters
test ActivityInstrumentationTestCase: The test case that is being run
v ViewGroup: The ViewGroup that should be dragged

scrollToTop

Added in API level 3
void scrollToTop (InstrumentationTestCase test, 
                Activity activity, 
                ViewGroup v)

通过反复调用 dragQuarterScreenDown(InstrumentationTestCase, Activity)将ViewGroup滚动到顶部

Parameters
test InstrumentationTestCase: The test case that is being run
activity Activity: The activity that is in the foreground of the test case
v ViewGroup: The ViewGroup that should be dragged

tapView

Added in API level 1
void tapView (InstrumentationTestCase test, 
                View v)

模拟触摸视图中心并快速释放(轻拍超时之前)。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be clicked

touchAndCancelView

Added in API level 1
void touchAndCancelView (InstrumentationTestCase test, 
                View v)

模拟触摸视图的中心并取消(所以没有onClick应该触发等)。

Parameters
test InstrumentationTestCase: The test case that is being run
v View: The view that should be clicked

Hooray!