我正在开发一个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)
请帮忙。谢谢!
答案 0 :(得分:2)
if (!_mViewPager.isFakeDragging()) {
_mViewPager.beginFakeDrag();
} else {
_mViewPager.endFakeDrag();
}
我希望它有所帮助。