java.lang.UnsupportedOperationException:RecyclerView不支持滚动到一个绝对位置不支持、位置、lang、java

2023-09-04 23:33:56 作者:立场一个浪

收到此错误三星GT-S7562的Andr​​oid 4.0.4。我不是要求通过code scrollTo方法。这是越来越内部调用。请帮忙

  java.lang.UnsupportedOperationException:RecyclerView不支持滚动到一个绝对位置。
            在android.support.v7.widget.RecyclerView.scrollTo(RecyclerView.java:941)
            在android.view.View.setScrollX(View.java:7010)
            在android.animation.PropertyValues​​Holder.nCallIntMethod(本机方法)
            在android.animation.PropertyValues​​Holder.access $ 200(PropertyValues​​Holder.java:35)
            在android.animation.PropertyValuesHolder$IntPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:815)
            在android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:476)
            在android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1145)
            在android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:551)
            在android.animation.LayoutTransition.startChangingAnimations(LayoutTransition.java:813)
            在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1805)
            在android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2632)
            在android.os.Handler.dispatchMessage(Handler.java:99)
            在android.os.Looper.loop(Looper.java:137)
            在android.app.ActivityThread.main(ActivityThread.java:4517)
            在java.lang.reflect.Method.invokeNative(本机方法)
            在java.lang.reflect.Method.invoke(Method.java:511)
            在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:993)
            在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
            在dalvik.system.NativeStart.main(本机方法)
 

解决方案

您将收到此错误的一些三星,索尼,... ICS的实现。这两个我已经成立,包括奇怪的内部视图管理层。 一种解决方法是延长 RecyclerView (或类产生的问题),用自己的类并使用一个。在这种类,你会基本上是吃的所有可能使这些设备异常。这是丑陋的,这太可怕了,但它是所有我能做些什么来解决这样的问题。

Java 混淆工具 ProGuard 之初体验

有关您与scrollTo具体问题....

 包com.stackoverflow.customviews;

公共类CustomRecyclerView扩展RecyclerView {

  私有静态最后字符串变量=CustomRecyclerView;

  公共CustomRecyclerView(android.content.Context上下文){
    超(上下文);
  }

  公共CustomRecyclerView(android.content.Context背景下,android.util.AttributeSet ATTRS){
      超(背景下,ATTRS);
  }

  公共CustomRecyclerView(android.content.Context背景下,android.util.AttributeSet ATTRS,INT defStyle){
      超(背景下,ATTRS,defStyle);
  }

  @覆盖
  公共无效scrollTo(INT X,int y)对{
      Log.e(TAG,CustomRecyclerView不支持滚动到一个绝对位置。);
     //要么不叫超在这里,或致电只是某些手机,或者尝试抓住它。从默认的实现,我们已经删除了运行时异常trown
  }
}
 

然后你就可以在你的布局XML替换此新类:

 <的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
  的xmlns:工具=htt​​p://schemas.android.com/tool​​s
  机器人:layout_width =match_parent
  机器人:layout_height =WRAP_CONTENT>

< com.stackoverflow.customviews.CustomRecyclerView
    机器人:ID =@ + ID / my_view
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:overScrollMode =从不
    机器人:滚动条=垂直/>

< /的FrameLayout>
 

Getting this error on Samsung GT-S7562 Android 4.0.4. I am not calling scrollTo method through code. It is getting called internally. Please help

java.lang.UnsupportedOperationException: RecyclerView does not support scrolling to an absolute position.
            at android.support.v7.widget.RecyclerView.scrollTo(RecyclerView.java:941)
            at android.view.View.setScrollX(View.java:7010)
            at android.animation.PropertyValuesHolder.nCallIntMethod(Native Method)
            at android.animation.PropertyValuesHolder.access$200(PropertyValuesHolder.java:35)
            at android.animation.PropertyValuesHolder$IntPropertyValuesHolder.setAnimatedValue(PropertyValuesHolder.java:815)
            at android.animation.ObjectAnimator.animateValue(ObjectAnimator.java:476)
            at android.animation.ValueAnimator.animationFrame(ValueAnimator.java:1145)
            at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:551)
            at android.animation.LayoutTransition.startChangingAnimations(LayoutTransition.java:813)
            at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1805)
            at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2632)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4517)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
            at dalvik.system.NativeStart.main(Native Method)

解决方案

You will get this error on some Samsung, Sony,... Implementation of ICS. Both I've founded that include strange internal view managements. One solution to this is to extend RecyclerView (Or the class that generate the issue) with your own class and use that one. In that class you will basically "eat" all possible render exceptions for these devices. It's ugly, it's awful but it's all what I can do to fix this kind of issues.

For your specific issue with scrollTo....

package com.stackoverflow.customviews;

public class CustomRecyclerView extends RecyclerView{

  private static final String TAG = "CustomRecyclerView";

  public CustomRecyclerView(android.content.Context context) {
    super(context);
  }

  public CustomRecyclerView(android.content.Context context, android.util.AttributeSet attrs) {
      super(context, attrs);
  }

  public CustomRecyclerView(android.content.Context context, android.util.AttributeSet attrs, int defStyle) {
      super(context, attrs, defStyle);
  }

  @Override
  public void scrollTo(int x, int y) {
      Log.e(TAG, "CustomRecyclerView does not support scrolling to an absolute position.");
     // Either don't call super here or call just for some phones, or try catch it. From default implementation we have removed the Runtime Exception trown 
  }
}

Then you can replace in your layout xml this new class:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">

<com.stackoverflow.customviews.CustomRecyclerView
    android:id="@+id/my_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:overScrollMode="never"
    android:scrollbars="vertical" />

</FrameLayout>