问题描述
我正在尝试在我的项目中实现这一点:https://github.com/SergeyBurlaka/CollapsingAvatarToolbarSample
在我的主要片段的 xml 文件中
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl_root_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior=".utils.FlingBehavior">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/top_head_height"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
当我尝试用午餐时,应用程序崩溃并显示此日志
android.view.InflateException: Binary XML file line #10 in it.archeometra.q8.quaser.debug:layout/fragment_main_test: Could not inflate Behavior subclass it.archeometra.q8.quaser.debug.utils.FlingBehavior
Caused by: java.lang.RuntimeException: Could not inflate Behavior subclass it.archeometra.q8.quaser.debug.utils.FlingBehavior
这是FlingBehavior类的代码
class FlingBehavior : AppBarLayout.Behavior() {
companion object {
private val TOP_CHILD_FLING_THRESHOLD = 3
}
private var isPositive = false
override fun onnestedFling(
coordinatorLayout: CoordinatorLayout,child: AppBarLayout,target: View,veLocityX: Float,veLocityY: Float,consumed: Boolean
): Boolean {
var veLocityY = veLocityY
var consumed = consumed
if (veLocityY > 0 && !isPositive || veLocityY < 0 && isPositive) {
veLocityY *= -1
}
if (target is RecyclerView && veLocityY < 0) {
val recyclerView = target
val firstChild = recyclerView.getChildAt(0)
val childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild)
consumed = childAdapterPosition > TOP_CHILD_FLING_THRESHOLD
}
return super
.onnestedFling(coordinatorLayout,child,target,veLocityX,veLocityY,consumed)
}
override fun onnestedPreScroll(
coordinatorLayout: CoordinatorLayout,dx: Int,dy: Int,consumed: IntArray,type: Int
) {
super.onnestedPreScroll(coordinatorLayout,dx,dy,consumed,type)
isPositive = dy > 0
}
}
我做错了什么?
编辑:我也尝试使用 github 项目中确切的 FlingBehavior 类,但它还是崩溃了。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)