2013-07-18 111 views
2

我正在開發一個android應用程序,在那裏我使用ViewPager的fakedrag創建圖像幻燈片。默認情況下,ontouch會被禁用。我會在觸摸時停止拖動過程。我嘗試以下方式聯繫,停止fakedrag觸摸android

@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) 

請幫忙。謝謝!

回答

1
if (!_mViewPager.isFakeDragging()) { 
    _mViewPager.beginFakeDrag(); 
} else { 
    _mViewPager.endFakeDrag(); 
} 

我希望它有幫助。