public class TouchUtils
extends Object
| java.lang.Object | |
| android.test.TouchUtils | |
此类在API级别24中已被弃用。
改为使用Espresso UI testing framework 。 新的测试应该使用Android Testing Support Library编写 。
用于生成触摸事件的可重用方法。 这些方法可以与InstrumentationTestCase或ActivityInstrumentationTestCase2一起使用,通过触摸屏模拟用户与应用程序的交互。
Public constructors |
|
|---|---|
TouchUtils() |
|
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
void clickView (InstrumentationTestCase test, View v)
模拟触摸视图的中心并释放。
| 参数(Parameters) | |
|---|---|
test |
InstrumentationTestCase: The test case that is being run |
v |
View: The view that should be clicked |
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 |
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 |
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 |
void dragQuarterScreenDown (ActivityInstrumentationTestCase test)
此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已弃用,因此支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项
模拟屏幕中央的触摸并向下拖动四分之一处
| 参数(Parameters) | |
|---|---|
test |
ActivityInstrumentationTestCase: The test case that is being run |
void dragQuarterScreenUp (ActivityInstrumentationTestCase test)
此方法在API级别3中已被弃用。
ActivityInstrumentationTestCase已被弃用,以支持ActivityInstrumentationTestCase2 ,该选项为配置被测活动提供了更多选项
模拟屏幕中心的触摸并向上拖动四分之一
| 参数(Parameters) | |
|---|---|
test |
ActivityInstrumentationTestCase: The test case that is being run |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
void dragViewToTop (InstrumentationTestCase test, View v)
模拟触摸视图的中心并拖动到屏幕顶部。
| 参数(Parameters) | |
|---|---|
test |
InstrumentationTestCase: The test case that is being run |
v |
View: The view that should be dragged |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
void longClickView (InstrumentationTestCase test, View v)
模拟触摸视图的中心,持续到长按,然后释放。
| 参数(Parameters) | |
|---|---|
test |
InstrumentationTestCase: The test case that is being run |
v |
View: The view that should be clicked |
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 |
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 |
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 |
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 |
void tapView (InstrumentationTestCase test, View v)
模拟触摸视图中心并快速释放(轻拍超时之前)。
| 参数(Parameters) | |
|---|---|
test |
InstrumentationTestCase: The test case that is being run |
v |
View: The view that should be clicked |
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 |