画廊ImageAdapter convertView总是空 [英] Gallery ImageAdapter convertView is always null

查看:208
本文介绍了画廊ImageAdapter convertView总是空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用与ImageAdapter图库与该拉的图像从我的资源ImageViews加载它。我的问题是,被传递给getView()方法,在我的适配器convertView总是空。这意味着新的ImageView创建每一次getView()被调用。这将导致可怕的preformance因为GC是不断运行擦去所有这些创造和不再使用的ImageView。

I am using a Gallery with an ImageAdapter to load it with ImageViews that pull images out of my resources. My problem is that the convertView that gets passed to the getView() method in my adapter is always null. This means that a new ImageView is created each and every time getView() is called. This leads to horrible preformance because the GC is constantly running to wipe away all of these created and no longer used ImageView's.

这显然是一个已知的bug:画廊的视图缓存坏了;从来没有转换的观点。

This is apparently a known bug: Gallery's view cache is broken; never converts views..

我的两个preferred解决方案的意见适配器本身或者1.手柄上的高速缓存,并采取一切重新正确地使用它们所需的逻辑照顾。 或2.包括图库小部件的我自己的副本并尝试修复它,所以它正确地返回循环的观点。

My two preferred solutions are either 1. handle a cache of views in the adapter itself and take care of all the logic required to re-use them properly. or 2. include a my own copy of the Gallery widget and try to fix it so it properly returns recycled views.

我已经开始实施的选项之一,但我很快意识到我并不确切地知道如何使所有的操作背后的逻辑。我开始时认为,方案二可能会更容易。

I've started implementing option one but am quickly realizing I don't exactly know how to make all of the logic behind that operation. I am begining to think that option two might be easier.

我已经找到了code在这里图库部件:<一href="http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/widget/Gallery.java">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/2.1_r2/android/widget/Gallery.java

I've found the code for the Gallery widget here: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/widget/Gallery.java

我不完全理解,但我可以看到它正在调用

I don't fully understand it, but I can see that it is calling

child = mAdapter.getView(position, null, this);

在线745.我(瞎猜)猜测,这是问题的根源。

on line 745. My (shot in the dark) guess that this is the root of the problem.

有没有人有这个错误的经验。或者,任何人都可以点我在正确的方向搞清楚如何回收情况的工作,这样我可以调整这个小工具才能正常工作?甚至认为我也许忽略了一些替代选项。

Does anyone have experience with this bug. Or can anyone point me in the right direction for figuring out how the recycler situation works so that I can tweak this widget to work correctly? Or even suggest some alternate option that I may be overlooking.

编辑:是我迄今发现的最好的解决办法是叫EcoGallery的实现。我能找到提到它网上了唯一的地方,在这里。为了得到它的工作,你必须把每块从那里在正确的位置在项目中。

The best solution that I ever found was an implementation called EcoGallery. The only place I can find reference to it online anymore is here. To get it working you have to put each chunk from there in the correct place within your project.

推荐答案

与特别是臭虫没有经验,但我已经做了自定义缓存之前,第三方观点寻呼机(支持LIB之前)。

No experience with that bug particularly, but I have done custom caching before with a 3rd party view pager (before the support lib).

这真的不是太难诚实。就我而言,我知道会有,顶多屏幕上的一个项目。但我也希望项目向左,右为preloaded(这些是webviews提取数据断网)。所以,我有3次一个简单的数组。

It's really not too difficult honestly. In my case, I knew there would be, at most, one item on the screen. But I also wanted the item to the left and right to be preloaded (these were webviews pulling data off the net). So I have a simple array of 3 views.

[V1, V2, V3]

现在你需要做的唯一事情是相互关联的适配器的位置在缓存的位置。有多种方法可以解决这个问题。当我第一次飙升出来,我只是做任何我目前的观点是要V2和翻转寻呼机时,旋转阵列的项目周围。所以,翻转到下一个视图将改变我的数组

Now the only thing you need to do is correlate a position in your adapter to a position in your cache. There's a variety of ways you could tackle this. When I first spiked it out, I just made whatever my current view was to be V2 and the rotated the items of the array around when flipping the pager. So flipping to the next view would alter my array

[V2, V3, V1]

很简单跟上。或者您也可以做数学和计算位置缓存的相对位置。

Was simple to keep up with. Or you could just do the math and calculate a position to a relative position of the cache.

另一种方法是创建一个最后,先出队列。回收的意见通过将它们推到队列中,当你需要一个视图,只是弹出一个来自它。

Another approach is to create a last in, first out queue. Recycle views by pushing them into the queue, and when you need a view, just pop one from it.

这篇关于画廊ImageAdapter convertView总是空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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