记录一下学习中最近偶遇两次这个错误:
java.lang.NoSuchMethodError: No static method onPullDistance(Landroid/widget/EdgeEffect;FF)F in class Landroidx/core/widget/EdgeEffectCompat; or its super classes (declaration of 'androidx.core.widget.EdgeEffectCompat' appears in /data/app/com.jiangxue.heartview-sDxXREwWLDMCpWawbYlahw==/base.apk)
debug一下最近问题定位到了这里
public static float onPullDistance(
@NonNull EdgeEffect edgeEffect,
float deltaDistance,
float displacement
) {
if (BuildCompat.isAtLeastS()) {
return Api31Impl.onPullDistance(edgeEffect, deltaDistance, displacement);
}
onPull(edgeEffect, deltaDistance, displacement);
return deltaDistance;
}
为什么突然间滑动边缘时不设置边缘效果会报错,首先检查一下对应版本问题
看一下我的布局
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<!-- <import type="com.jiangxue.heartview.R" />-->
<variable
name="viewModel"
type="com.jiangxue.heartview.ui.main.fragment.FateViewModel" />
</data>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_topic"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</layout>
试着布局修改后正常了:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="viewModel"
type="com.jiangxue.heartview.ui.main.fragment.FateViewModel" />
</data>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_topic"
android:overScrollMode="never"
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</layout>
这行代码:试着禁掉边缘效果
android:overScrollMode="never" 可以设置滑动到边缘时的光晕效果
android:overScrollMode=""
有三个属性
never:去掉光晕效果
always:设置总是出现光晕效果
ifContentScrolls:设置此模式,如果recycleview里面的内容可以滑动,那么滑到边界后继续滑动会出现弧形光晕;如果recycleview里面的内容不可以滑动,那么滑到边界后继续滑动不会出现弧形光晕
试着降低版本
implementation 'androidx.recyclerview:recyclerview:1.3.0'
到
implementation 'androidx.recyclerview:recyclerview:1.1.0'
也OK
总结一下解决办法:
办法一:
implementation 'androidx.recyclerview:recyclerview:1.1.0'
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_topic"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
办法二:
implementation 'androidx.recyclerview:recyclerview:1.3.0'
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_topic"
android:overScrollMode="never"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
收工!