在自定义布局回收意见 [英] Recycling views in custom layout

查看:256
本文介绍了在自定义布局回收意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现自定义布局。这是一个异质网格,看起来像下面这样,除了一个事实,即瓷砖将与一些文字图像。此外,它有一个动画效果 - 底层数据改变时(添加,删除的项目,重新排序)有一个动画,每个块移动到新的位置。而这完美的作品。

I'm implementing a custom layout. It's a heterogenous grid and will look like the one below, except for the fact, that the tiles will be images with some text. Additionally it has an animation effect - each time the underlying data is changed (items added, removed, reordered) there's an animation, each tile moves to its new position. And this works perfectly.

整个事情是一个滚动型里面。当用户启动应用程序,一些地砖(20最多)出现。当他到达滚动的底部,新的地砖被装入。瓷砖是 RelativeLayouts

The whole thing is inside a ScrollView. When user starts app, a few tiles (20 at most) appear. As he reaches the bottom of the scroll, new tiles get loaded. The tiles are RelativeLayouts.

我的问题是关于意见的回收利用。其中接受多个子视图,如 ListView的典型布局的GridView 有一个回收机制。在滚动,当一个观点是不可见的,它的回收,它回来时,它的即将被用户再次看到。

My question concerns the recycling of views. Typical layouts which accept multiple subviews like ListView or GridView have a recycling mechanism. On scroll, when a view is not visible, it's recycled and it comes back when it's about to be seen by the user again.

我需要实现这样的行为?会发生什么,如果我不这么做?它甚至有可能实现它,因为我可能有新数据到达时进行动画处理的子视图(也这这将不能在布局的可见部分),以他们的新岗位。

Do I need to implement such a behaviour? What would happen if I don't? Is it even possible to implement it since I may have to animate the sub-views (also these which wouldn't be in the visible part of the layout) to their new positions when new data arrives.

或者,也许我应该只是回收位图时,他们的可见区域之外?这可能是在那里我可以打一个内存溢出,不是吗?

Or maybe I should just recycle the bitmaps when they're outside the visible area? This is probably where I could hit an OutOfMemory, isn't it?

推荐答案

我肯定会推荐的回收,特别是如果项目的数量实际上是无限的。

I'd definitely recommend recycling, especially if the number of items is effectively unlimited.

这其中,像你说的,将在很大程度上取决于处理位图的内存问题放在一边,不回收会造成颤动的更多的机会,当你在装载更多的物品。这是因为更多的意见将需要创建 - 而不是再生

Aside from memory issues which, like you say, will largely depend on handling of Bitmaps, not recycling will cause more chance of juddering when you load in more items. This is because more Views will need to be created - rather than recycled.

实现查看回收应该是很简单的,你正在使用的自定义布局定,只保留意见的高速缓存,并按照类似于Android的适配器类(即 getView(INT位置,查看convertView格局。 。)。当你需要从动画屏幕外视图,你会使用 getView()来获得一个未使用的查看和更新​​,以包含你的模型数据(如果你不使用MVC对于这一点,我会推荐它)。

Implementing View recycling should be quite straightforward given you're using a custom layout, just keep a cache of Views and follow the Pattern similar to Android's Adapter class (i.e. getView(int position, View convertView ..). When you need to animate a View from offscreen, you'll use getView() to get an unused View and update it to contain your model data (if you're not using MVC for this, I'd recommend it).

这篇关于在自定义布局回收意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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