Snackbar的轻扫以解散冻结应用程序

问题描述 投票:2回答:2

快速背景:

我有一个FragmentActivity,它包含我在我的应用程序中显示的所有视图组件,特别是CoordinatorLayout视图,用于我为实现刷卡到解雇效果而制作的任何零食栏。

活动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中的差异变化,但我没有看到任何涉及的支持类的变化。任何人都可以提供帮助或任何暗示突然出错的提示吗?

android kotlin android-fragmentactivity android-coordinatorlayout android-snackbar
2个回答
0
投票

我在CoordinatorLayout中有一个类似的问题,内部SwipeRefreshLayout,其中swipe-to-dismiss停止工作,并在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轻扫一下。

它仍然会像以前一样抛出相同的错误,但是,像之前一样,不会使应用程序崩溃。


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)

© www.soinside.com 2019 - 2024. All rights reserved.