我有一个 Android View ,我正在检测用于执行操作的滑动手势,我想编写一些测试来验证该手势是否正常工作。我已经尝试过 TouchUtils.dragViewTo 和 TouchUtils.drag (步骤很少),但这些似乎都没有触发事件。
有没有办法模拟fling手势?
最佳答案
好吧,这是一个非常古老的问题,但是发布一个对我有用的解决方案,可能会帮助其他来搜索这个问题的人
int[] xy = new int[2];
View v = currentActivity.getCurrentFocus();
v.getLocationOnScreen(xy);
final int viewWidth = v.getWidth();
final int viewHeight = v.getHeight();
final float x = xy[0] + (viewWidth / 2.0f);
float fromY = xy[1] + (viewHeight / 2.0f);
int screenWidth = currentActivity.getWindowManager().getDefaultDisplay().getWidth();
//Drag from centre of screen to Leftmost edge of display
TouchUtils.drag(this, (screenWidth - 1), x, fromY, fromY , 5); //Vary the last parameter to sdjust speed of fling
关于android - 在Android ActivityInstrumentationTestCase2中模拟一个fling手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3996144/