我正在开发一个 android 应用程序,我正在使用 ViewPager 的 fakedrag 创建图像幻灯片。默认情况下,ontouch 被禁用。我想在触摸时停止拖动过程。我尝试了以下联系方式,
@Override
public boolean onTouch(View v, MotionEvent event)
{
if(_mViewPager.getId() == v.getId())
{
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
_mViewPager.beginFakeDrag();
_mViewPager.endFakeDrag();
}
}
return false;
}
但是,上面的代码给出了一个强制关闭。请看下面的错误日志,
07-18 14:09:12.568: E/AndroidRuntime(17547): FATAL EXCEPTION: main
07-18 14:09:12.568: E/AndroidRuntime(17547): java.lang.IllegalStateException: No fake drag in progress. Call beginFakeDrag first.
07-18 14:09:12.568: E/AndroidRuntime(17547): at android.support.v4.view.ViewPager.fakeDragBy(ViewPager.java:2313)
07-18 14:09:12.568: E/AndroidRuntime(17547): at com.exmp.myapp.learn.alphabets.AlphaPager$3$1.run(AlphaPager.java:454)
07-18 14:09:12.568: E/AndroidRuntime(17547): at android.os.Handler.handleCallback(Handler.java:605)
07-18 14:09:12.568: E/AndroidRuntime(17547): at android.os.Handler.dispatchMessage(Handler.java:92)
07-18 14:09:12.568: E/AndroidRuntime(17547): at android.os.Looper.loop(Looper.java:137)
07-18 14:09:12.568: E/AndroidRuntime(17547): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 14:09:12.568: E/AndroidRuntime(17547): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 14:09:12.568: E/AndroidRuntime(17547): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 14:09:12.568: E/AndroidRuntime(17547): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 14:09:12.568: E/AndroidRuntime(17547): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 14:09:12.568: E/AndroidRuntime(17547): at dalvik.system.NativeStart.main(Native Method)
请帮忙。谢谢!