问题描述
我需要模拟 DragEvent
进行测试。但是,我无法访问 DragEvent.obtain()
方法。
I need to simulate DragEvent
for testing purpose. However I am not able to access DragEvent.obtain()
method.
请建议一种方式模拟DragEvent
,以便我可以为DragListener的onDrag()方法定义DragEvent的操作
Please suggest a way to simulate DragEvent
such that I can define actions for DragEvent in onDrag() method of DragListener
对于Touch MotionEvent,我们可以这样做通过MotionEvent.obtain()和传递相关参数,但是如果DragEvent
For Touch MotionEvent, we could do so by MotionEvent.obtain() and passing relevant parameters, however this method is not accessible in case of DragEvent
推荐答案
DragEvent .obtain()是一个内部的API函数,它不被 @hide 注释所显示。
DragEvent.obtain() is an internal API function which is not exposed yet as seen by @hide annotation.
作为解决方法,您可以从包裹对象
As a wayaround, you can create a DragEvent from parcelable objecthttp://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.3_r1/android/view/DragEvent.java#488
DragEvent.CREATOR.createFromParcel(parcel);
Parcel parcel = Parcel.obtain();
parcel.writeInt(action);
parcel.writeFloat(x);
parcel.writeFloat(y);
parcel.writeInt(0); // Result
parcel.writeInt(0); // No Clipdata
parcel.writeInt(0); // No Clip Description
parcel.setDataPosition(0);
如果要添加Clipdata,请参阅createFromParcel()方法。
If you want to add Clipdata, see it's createFromParcel() method.
这篇关于如何在Android中创建DragEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!