壁画:图像滚动RecylcerView后dissapear [英] Fresco: Images dissapear after scrolling RecylcerView

查看:594
本文介绍了壁画:图像滚动RecylcerView后dissapear的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水平RecyclerView:每件商品都有使用Facebook壁画图像库加载到它的图像。然而,尽管最初的正确加载图像,因为它是滚动了一下到屏幕上,当RecyclerView进一步滚动消失。

此外,还有在那里来回滚动放错了图像中的错误的项目的问题(我想这是与回收viewholders一个问题)。这就是说,你可以看到覆盖在下面的屏幕截图中的项目文本始终一贯地显示在正确的项目,所以这个问题,回收是独家图片。

我可以确认我传递每次SimpleDraweeView正确的URL。

下面是一些屏幕和伴随的日志:

截图之一,示出了从右侧

截图1:显示正确的图像从右侧进入

日志,因为这被滚动到屏幕上,图像被成功加载:

\r
\r

AbstractDraweeController:控制器cbb6b5b 5:onTouchEvent MotionEvent {行动= ACTION_DOWN,actionButton = 0,编号[0] = 0,X [0] = 32.860107,Y [0] = 198.16406,Tooltype刀具[0] = TOOL_TYPE_FINGER,buttonState = 0,亚状态= 0,标志=为0x0,edgeFlags =为0x0,pointerCount = 1,historySize = 0,EVENTTIME = 464189,停工= 464189,DEVICEID = 0,源= 0x1002}\r
AbstractDraweeController:控制器c077610 8:setHierarchy:com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12\r
AbstractDraweeController:控制器87baf9c空 - > 9:初始化\r
AbstractDraweeController:控制器c077610 8:setHierarchy:空\r
AbstractDraweeController:控制器87baf9c 9:setHierarchy:com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12\r
AbstractDraweeController:控制器87baf9c 9:onAttach:请求需要提交\r
PipelineDraweeController:控制器87baf9c:了getDataSource\r
AbstractDraweeController:控制器87baf9c 9:submitRequest:数据源:ad37da5\r
BufferedDiskCache:找不到图像在临时区域http://i.imgur.com/OVwFM9ub.jpg\r
BufferedDiskCache:磁盘缓存读取http://i.imgur.com/OVwFM9ub.jpg\r
BufferedDiskCache:磁盘高速缓存中找到条目http://i.imgur.com/OVwFM9ub.jpg\r
NativeMemoryChunkPool:用于=(7,188416);自由=(0,0)\r
NativeMemoryChunkPool:得到(ALLOC)(对象大小)=(ef2f57a,16384)\r
GenericByteArrayPool:用=(1,16384);自由=(0,0)\r
GenericByteArrayPool:获得(复用)(物体大小)=(cf34727,16384)\r
GenericByteArrayPool:发布(再利用)(对象大小)=(cf34727,16384)\r
GenericByteArrayPool:用于=(0,0);免费=(1,16384)\r
BufferedDiskCache:从磁盘缓存读取成功的http://i.imgur.com/OVwFM9ub.jpg\r
TiffUtil:不支持的方向\r
BitmapPool:用于=(7,2831360);自由=(0,0)\r
BitmapPool:得到(ALLOC)(对象大小)=(8622988,102400)\r
AbstractDraweeController:控制器87baf9c 9:set_final_result @ onNewResult:图片:CloseableReference 1a34f21

\r

\r
\r

在这里输入的形象描述

截图2:示出了由右至左进一步滚动后RecyclerView。这表明是pviously装入ViewHolder $ P $现在已经消失的形象。

以下日志截图1和2之间产生:

\r
\r

AbstractDraweeController:控制器cbb6b5b 5:onTouchEvent MotionEvent {行动= ACTION_DOWN,actionButton = 0,编号[0] = 0,X [0] = 103.65283,Y [0] = 144.14063,Tooltype刀具[0] = TOOL_TYPE_FINGER,buttonState = 0,亚状态= 0,标志=为0x0,edgeFlags =为0x0,pointerCount = 1,historySize = 0,EVENTTIME = 793409,停工= 793409,DEVICEID = 0,源= 0x1002}\r
AbstractDraweeController:控制器87baf9c 9:onDetach\r
AbstractDraweeController:控制器e14aa9d 2:onDetach\r
AbstractDraweeController:控制器87baf9c 9:释放:图片:CloseableReference 1a34f21\r
AbstractDraweeController:控制器e14aa9d 2:发布:图片:CloseableReference 61f0be9

\r

\r
\r

code:
ViewHolder XML

\r
\r

<?XML版本=1.0编码=UTF-8? >\r
<的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android\r
    的xmlns:壁画=htt​​p://schemas.android.com/apk/res-auto\r
    机器人:layout_width =120dp\r
    机器人:layout_height =match_parent\r
    机器人:背景=#993366>\r
\r
    < com.facebook.drawee.view.SimpleDraweeView\r
        机器人:ID =@ + ID / recycler_drawee_view\r
        机器人:layout_width =110dp\r
        机器人:layout_height =match_parent\r
        机器人:背景=#336699\r
        壁画:placeholderImage =@绘制/占位符/>\r
\r
    <的TextView\r
        机器人:ID =@ + ID / recycler_text_view\r
        机器人:layout_width =WRAP_CONTENT\r
        机器人:layout_height =WRAP_CONTENT\r
        机器人:文字=TEST/>\r
\r
< /&的FrameLayout GT;

\r

\r
\r

code:SimpleDraweeView设置

\r
\r

GenericDraweeHierarchyBuilder建设者=\r
                新GenericDraweeHierarchyBuilder(context.getResources());\r
mHierarchy =建设者\r
       .setFadeDuration(300)\r
       .setPlaceholderImage(context.getDrawable(R.drawable.placeholder))\r
       。建立();\r
\r
...\r
\r
mDraweeView.setHierarchy(mHierarchy);\r
URI URI = Uri.parse(IMAGELINK);\r
DraweeController控制器= Fresco.newDraweeControllerBuilder()\r
.setUri(URI)\r
。建立();\r
mDraweeView.setController(控制器);

\r

\r
\r

code:RecyclerView.Adapter

\r
\r

@覆盖\r
公共SimpleHolder onCreateViewHolder(ViewGroup中ViewGroup中,int i)以{\r
查看查看= LayoutInflater.from(mContext).inflate(R.layout.recycler_view_item,ViewGroup中,FALSE);\r
返回新SimpleHolder(查看,mHierarchy);\r
}\r
\r
...\r
\r
@覆盖\r
公共无效onBindViewHolder(RecyclerView.ViewHolder持有人,最终诠释位置){\r
holder.setText(EntryUtils.getFullCaption(mData.get(位置)));\r
holder.setImage(EntryUtils.getThumbnailLink(mData.get(位置)));\r
}

\r

\r
\r谢谢你的时间,如果你得到了这个远。请让我知道,如果进一步的细节可能是有用的,我会尽量提供他们。

再次感谢。


解决方案

从logcat中,你可以看到你正在使用DraweeHierarchy的同一个实例与多个控制器。不这样做。

  AbstractDraweeController:控制器c077610 8:setHierarchy:com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12
AbstractDraweeController:控制器87baf9c空 - > 9:初始化
AbstractDraweeController:控制器c077610 8:setHierarchy:空
AbstractDraweeController:控制器87baf9c 9:setHierarchy:com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12

由于在文档解释,不要再使用 DraweeHierarchies 。每个 DraweeView 需要有其自身的 DraweeHierarchy 实例。不要层级存储在 mHierarchy ,只需设置层次结构视图。

此外,每个视图需要自己的层次,但是,这并不意味着你必须要设置一个新的形象,每次建立一个新的层次。在构建层次只有一次,当你创建视图,仅此而已。后来,当你需要设置/更改图像,只需设置一个新的控制器到视图。

从你的例子似乎你并不需要建立层次结构编程的。您可以同时指定衰落期和XML的占位符。顺便说一句,对于淡入时间默认值是300毫秒,所以你其实可以省略的部分了。
所以,只要删除code,它建立并设置层次结构( mDraweeView.setHierarchy(mHierarchy))。

如果你只使用URI没有任何额外的选项,你不需要建立控制器。只要做到 mDraweeView.setImageURI(URI) SimpleDraweeView 会为你创建控制器。

I have a Horizontal RecyclerView: each item has an image loaded into it using the Facebook Fresco image library. However, while the correct image loads initially as it is scrolled a bit onto the screen, it disappears when the RecyclerView is scrolled further.

In addition, there are issues where scrolling back and forth puts the wrong image in the wrong item (I assume this is an issue with recycling the viewholders). That said, the text you can see overlaying the items in the below screen shot always displays consistently on the correct item, so this recycling issue is exclusive to the images.

I can confirm I am passing the SimpleDraweeView the correct URL each time.

Below are some screens and accompanying logs:

Screenshot 1: showing the correct image entering from the right.

Logs as this is scrolled onto the screen and the image is successfully loaded:

AbstractDraweeController: controller cbb6b5b 5: onTouchEvent MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=32.860107, y[0]=198.16406, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=464189, downTime=464189, deviceId=0, source=0x1002 }
AbstractDraweeController: controller c077610 8: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12
AbstractDraweeController: controller 87baf9c null -> 9: initialize
AbstractDraweeController: controller c077610 8: setHierarchy: null
AbstractDraweeController: controller 87baf9c 9: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12
AbstractDraweeController: controller 87baf9c 9: onAttach: request needs submit
PipelineDraweeController: controller 87baf9c: getDataSource
AbstractDraweeController: controller 87baf9c 9: submitRequest: dataSource: ad37da5
BufferedDiskCache: Did not find image for http://i.imgur.com/OVwFM9ub.jpg in staging area
BufferedDiskCache: Disk cache read for http://i.imgur.com/OVwFM9ub.jpg
BufferedDiskCache: Found entry in disk cache for http://i.imgur.com/OVwFM9ub.jpg
NativeMemoryChunkPool: Used = (7, 188416); Free = (0, 0)
NativeMemoryChunkPool: get (alloc) (object, size) = (ef2f57a, 16384)
GenericByteArrayPool: Used = (1, 16384); Free = (0, 0)
GenericByteArrayPool: get (reuse) (object, size) = (cf34727, 16384)
GenericByteArrayPool: release (reuse) (object, size) = (cf34727, 16384)
GenericByteArrayPool: Used = (0, 0); Free = (1, 16384)
BufferedDiskCache: Successful read from disk cache for http://i.imgur.com/OVwFM9ub.jpg
TiffUtil: Unsupported orientation
BitmapPool: Used = (7, 2831360); Free = (0, 0)
BitmapPool: get (alloc) (object, size) = (8622988, 102400)
AbstractDraweeController: controller 87baf9c 9: set_final_result @ onNewResult: image: CloseableReference 1a34f21

Screenshot 2: showing the RecyclerView after scrolling further from right to left. This shows the image that was previously loaded into the ViewHolder has now disappeared.

The following logs are produced between Screenshot 1 and 2:

AbstractDraweeController: controller cbb6b5b 5: onTouchEvent MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=103.65283, y[0]=144.14063, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=793409, downTime=793409, deviceId=0, source=0x1002 }
AbstractDraweeController: controller 87baf9c 9: onDetach
AbstractDraweeController: controller e14aa9d 2: onDetach
AbstractDraweeController: controller 87baf9c 9: release: image: CloseableReference 1a34f21
AbstractDraweeController: controller e14aa9d 2: release: image: CloseableReference 61f0be9

Code: ViewHolder XML

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_width="120dp"
    android:layout_height="match_parent"
    android:background="#993366">

    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/recycler_drawee_view"
        android:layout_width="110dp"
        android:layout_height="match_parent"
        android:background="#336699"
        fresco:placeholderImage="@drawable/placeholder" />

    <TextView
        android:id="@+id/recycler_text_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TEST" />

</FrameLayout>

Code: SimpleDraweeView setup

GenericDraweeHierarchyBuilder builder =
                new GenericDraweeHierarchyBuilder(context.getResources());
mHierarchy = builder
       .setFadeDuration(300)
       .setPlaceholderImage(context.getDrawable(R.drawable.placeholder))
       .build();

...

mDraweeView.setHierarchy(mHierarchy);
Uri uri = Uri.parse(imageLink);
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(uri)
.build();
mDraweeView.setController(controller);

Code: RecyclerView.Adapter

@Override
public SimpleHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(mContext).inflate(R.layout.recycler_view_item, viewGroup, false);
return new SimpleHolder(view, mHierarchy);
}

...

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
holder.setText(EntryUtils.getFullCaption(mData.get(position)));
holder.setImage(EntryUtils.getThumbnailLink(mData.get(position)));
}

Thank you for your time if you got this far. Please let me know if further details could be useful and I will try to supply them.

Thanks again.

解决方案

From the logcat you can see that you are using the same instance of DraweeHierarchy with multiple controllers. Do not do that.

AbstractDraweeController: controller c077610 8: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12
AbstractDraweeController: controller 87baf9c null -> 9: initialize
AbstractDraweeController: controller c077610 8: setHierarchy: null
AbstractDraweeController: controller 87baf9c 9: setHierarchy: com.facebook.drawee.generic.GenericDraweeHierarchy@d36ab12

As explained in the documentation, do not re-use DraweeHierarchies. Each DraweeView needs to have its own instance of a DraweeHierarchy. Do not store the hierarchy in mHierarchy, just set the hierarchy to the view.

Also, each view needs its own hierarchy but that doesn't mean you have to build a new hierarchy each time you want to set a new image. You build the hierarchy only once, when you create the view and that's it. Later on when you need to set/change an image, just set a new controller to the view.

From your example it seems that you do not need to build the hierarchy programmatically at all. You can specify both the fade duration and the placeholder in XML. Btw, default value for fade-duration is 300ms so you can actually omit that part too. So, just remove the code that builds and sets the hierarchy (mDraweeView.setHierarchy(mHierarchy)).

If you are only using the Uri without any additional options, you do not need to build the controller. Just do mDraweeView.setImageURI(uri) and SimpleDraweeView will create the controller for you.

这篇关于壁画:图像滚动RecylcerView后dissapear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆