对于是否图库小部件的替换景观回收存在吗? [英] Does a replacement for Gallery widget with View recycling exist?

查看:87
本文介绍了对于是否图库小部件的替换景观回收存在吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android默认的库控件不回收的意见$ C> convertView 设置为null。

The default Gallery widget on Android does not recycle views - everytime the view for a new position is called the widget always calls the getView method of the adapter with convertView set to null.

在滚动向前和向后这结束了在很多观点被创造,其中回收组件图库并将其存储在似乎并没有迅速回收他们足够导致的OOM的情况。

As you scroll backwards and forwards this ends up in lots of views being created, which the recycler component that the Gallery stores them in does not seem to recycle them quickly enough leading to an OOM situation.

您可以用几个大十岁上下的图像作为你的库项目很容易测试,但只是一个TextView将导致它到底。将一个日志语句在柜台 getView 适配器的方法还看到有多少新的视图创建的。

You can test this easily with a few large-ish images as your gallery items, but just a TextView will cause it in the end. Put a log statement with a counter in the getView method of your adapter also to see how many new views are created.

难道一个第三方控件,它就像一个画廊,但也实现了看法回收存在吗?

Does a third-party widget which behaves like a Gallery but that also implements view recycling exist?

推荐答案

我的解决办法是,在年底,将与@ CommonsWare的建议,修改图库源$ C ​​$ C。这也需要复制下列文件:

My solution was, in the end, going with @CommonsWare's suggestion to modify the Gallery source code. This is also required copying the following files:

  • 适配器视图
  • AbsSpinner
  • AdapterView
  • AbsSpinner

但这些都是pretty的简单。

but these are pretty simple.

之后我修改code做到以下几点:

After that I modified code to do the following:

RECYCLEBIN AbsSpinner

      
  • 将在回收了一个又一个,而不是根据对象   定位
  •   
  • 从回收的底部检索对象,而不管   职位要求
  •   
  • 的现有实现假定在适配器每个不同位置   导致了一个独特的视角。上述变化是,如果您的照片包含唯一的好   只有一种类型的项目,如果没有你需要添加某种关键的基于项目类型   和所需的该类型的金额
  •   
  • Place objects in the recycler one after another, rather than according to position
  • Retrieve objects from the bottom of the recycler, regardless of the position requested
  • The existing implementation assumed that each different position in the adapter resulted in a unique view. The changes above are only good if your Gallery contains only one type of item, if not you'll need to add some sort of key based on item type and the amount of that type required

图库

      
  • 在使用反射(啊)来修改的ViewGroup 私人 mGroupFlags 变量,让孩子重新排序 - 我还设置一个布尔值,指示字段访问是否成功,我使用组件之前测试。
  •   
  • 删除所有呼叫 mRecycler.clear()
  •   
  • 数   项目库已显示   因为它滚动和现有变化   实施将清除   回收时(一)setSelection是   所谓的(B)发生的运动滚动
  •   
  • Used reflection (ugh) to modify the private mGroupFlags variable of ViewGroup to allow child re-ordering - I also set a boolean value indicating whether the field access succeeded which I test before using the component.
  • Removed all calls to mRecycler.clear()
  • The number of items the gallery has to display changes as it scrolls and the existing implementation would clear the recycler when (a) setSelection was called (b) a motion scroll occurred

通过这些修改我在我在我的适配器 NewView的法计数器达到... 7。

With these modifications my counter in my newView method in my adapter reached... 7.

这里是code (下的http://en.wikipedia.org/wiki/WTFPL

这篇关于对于是否图库小部件的替换景观回收存在吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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