快速背景:
我有一个FragmentActivity
,其中包含我在整个应用中显示的所有视图组件,特别是CoordinatorLayout
视图,用于我实现的任何 snackbars 轻扫到解雇的效果。
活动xml
<android.support.design.widget.CoordinatorLayout
android:id="@+id/cl_snackbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
活动类
@BindView(R.id.cl_snackbar) View snackBar;
/**
* To allow for use of a snackbar throughout the app's fragments
*/
public View getSnackBar() {
return snackBar;
}
片段类
@Nullable private View snackBar;
//This is done in fragment's onCreateView()
if (getActivity() instanceof ParentActivity) snackBar = ((ParentActivity) getActivity()).getSnackBar();
//This is done in a method
if (snackBar != null) Snackbar.make(snackBar, "Working", Snackbar.LENGTH_LONG).show();
此功能在过去一年中运行良好,但我最近将我的 Android支持库从26.1.0更新为27.0.0,并且刷卡到解雇效果现在完全冻结了应用程序。它变得反应迟钝。在logcat
我收到以下警告:
E/ViewDragHelper: Ignoring pointerId=0 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream.
E/ViewDragHelper: Ignoring pointerId=-1 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream.
E/ViewDragHelper: Ignoring pointerId=-1 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream.
E/ViewDragHelper: Ignoring pointerId=-1 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream.
我已经检查了Android 27.0.0中的 diff 更改,但我没有看到任何与所涉及的支持类相关的更改。任何人都可以提供帮助或任何关于突然出错的提示吗?
答案 0 :(得分:2)
删除滑动到解雇behaviour
应解决问题:
snackBar.addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onShown(transientBottomBar: Snackbar) {
val layoutParams = transientBottomBar.view.layoutParams as? CoordinatorLayout.LayoutParams
layoutParams?.let { it.behavior = null }
}
})
如果您需要保存行为,则应复制behaviour
并在处理触摸事件前插入requestDisallowInterceptTouchEvent(true)
,然后再插入requestDisallowInterceptTouchEvent(false)
。
答案 1 :(得分:0)
在带有内部SwipeRefreshLayout的CoordinatorLayout中,我遇到了类似的相同问题,其中,要擦除的解除停止工作,并在LogCat中抛出错误,但没有崩溃:
E/ViewDragHelper: Ignoring pointerId=0 because ACTION_DOWN was not received for this pointer before ACTION_MOVE. It likely happened because ViewDragHelper did not receive all the events in the event stream.
pointerId = -1也出现了同样的错误。
我的活动布局是:
<!-- cl_main is the SnackBar's host View -->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/cl_main"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/main_include_all_items"/>
</android.support.v4.widget.SwipeRefreshLayout>
</android.support.design.widget.CoordinatorLayout>
我认为SwipeRefreshLayout可能正在拦截滑动到达CoordinatorLayout的位置。
我通过将build.gradle中的compileSdkVersion和targetSdkVersion都升级到28,并将build.gradle中的依赖项都升级到28.0.0来解决/解决了这个问题(主要是)。完成此操作后,滑动滑动即可打开Snackbar。
它仍然会引发与以前相同的错误,但不会像以前那样使应用程序崩溃。