gpt4 book ai didi

android - VelocityTracker 在 Android 4.4 上导致崩溃

转载 作者:IT老高 更新时间:2023-10-28 23:40:51 26 4
gpt4 key购买 nike

在我的应用程序中,我有一个抽屉布局的自定义实现。它在 Android 2.3 和 4.0.4 上运行良好,但在 Android 4.4 上几乎每次我打开或关闭抽屉时都会崩溃。这是错误日志:

E/AndroidRuntime( 9839): FATAL EXCEPTION: main
E/AndroidRuntime( 9839): Process: com.andryr.launcher, PID: 9839
E/AndroidRuntime( 9839): java.lang.IllegalStateException: Already in the pool!
E/AndroidRuntime( 9839): at android.util.Pools$SimplePool.release(Pools.java:112)
E/AndroidRuntime( 9839): at android.util.Pools$SynchronizedPool.release(Pools.java:161)
E/AndroidRuntime( 9839): at android.view.VelocityTracker.recycle(VelocityTracker.java:85)
E/AndroidRuntime( 9839): at com.andryr.widget.DrawerLayout.onTouchEvent(DrawerLayout.java:131)
E/AndroidRuntime( 9839): at android.view.View.dispatchTouchEvent(View.java:7706)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
E/AndroidRuntime( 9839): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
E/AndroidRuntime( 9839): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
E/AndroidRuntime( 9839): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
E/AndroidRuntime( 9839): at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
E/AndroidRuntime( 9839): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
E/AndroidRuntime( 9839): at android.view.View.dispatchPointerEvent(View.java:7886)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
E/AndroidRuntime( 9839): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
E/AndroidRuntime( 9839): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
E/AndroidRuntime( 9839): at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime( 9839): at android.os.MessageQueue.next(MessageQueue.java:138)
E/AndroidRuntime( 9839): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 9839): at android.app.ActivityThread.main(ActivityThread.java:5001)
E/AndroidRuntime( 9839): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 9839): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
E/AndroidRuntime( 9839): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)

这是我的代码:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
if(!mInterceptTouchEvent)
{
return false;
}
if (ev.getAction() == MotionEvent.ACTION_DOWN
&& ((ev.getX() < ViewConfiguration.get(getContext())
.getScaledEdgeSlop() && !mExpanded) || (ev.getX() > getWidth()
- ViewConfiguration.get(getContext())
.getScaledEdgeSlop())
&& mExpanded))
{
if (mVelocityTracker == null)
mVelocityTracker = VelocityTracker.obtain();
else
mVelocityTracker.clear();
return true;
}
return false;
}

@Override
public boolean onTouchEvent(MotionEvent ev)
{
if(!mInterceptTouchEvent)
{
return false;
}
mLastMotionX = ev.getX();
if (mVelocityTracker == null)
return false;
switch (ev.getAction())
{
case MotionEvent.ACTION_MOVE:
mVelocityTracker.addMovement(ev);
mVelocityTracker.computeCurrentVelocity(1000);
mVelocity = mVelocityTracker.getXVelocity();
// ViewHelper.setTranslationX(mDrawerLayout,
// -mDrawerLayout.getWidth()
// + mLastMotionX);
// ViewHelper.setTranslationX(mRootView, mLastMotionX);
mPosition = (int) (-mDrawerLayout.getWidth() + mLastMotionX);
requestLayout();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:

if (Math.abs(mVelocity) > ViewConfiguration.get(getContext())
.getScaledMinimumFlingVelocity()
&& Math.abs(mVelocity) < ViewConfiguration
.get(getContext()).getScaledMaximumFlingVelocity())
{
if (mVelocity > 0)
{
openDrawer();

} else
{
closeDrawer();

}
} else
{
if (mLastMotionX > getWidth() / 2)
{
openDrawer();

} else
{
closeDrawer();

}
}

mVelocityTracker.recycle();
return false;

}
return true;
}

第 131 行是:

    mVelocityTracker.recycle();

我不明白为什么会这样。

最佳答案

回收后我必须将我的velocitytracker设置为null,以使其正常工作

关于android - VelocityTracker 在 Android 4.4 上导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26074907/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com