问题描述
我试图重新的ListView
(和 AbsListView
)的逻辑,以查看回收。我需要这一点,但我们可以说,这只是为了解Android的逻辑。
I'm trying to recreate ListView
(and AbsListView
) logic, with view recycling.I need this but we can say it's only for understand Android logic.
假如我的孩子们的项目是相同的(相同的布局),使用固定高度 RelativeLayout的
。
Suppose my children items are the same (same layout), using fixed height RelativeLayout
.
在滚动,我重用鬼儿查看和设置当前项目的属性。它的正常工作,因为我使用 View.offsetTopAndBottom()
和无效()
,而不是滚动过程中,要求布局进行优化。
During scrolling, I'm reusing ghost children view and set properties for current item.It's working fine, since I'm using View.offsetTopAndBottom()
and invalidate()
instead of requesting layout during scroll for optimization.
我的问题是更新的孩子( RelativeLayout的
)。
My problem is updating the children (RelativeLayout
).
取决于项目,我要隐藏或显示的ImageView
关于本项目。对于这一点,我只是用 iconImage.setVisibility(GONE)
和 iconImage.setVisibility(可见)
。
Depends of item, I want to hide or show ImageView
on this item. For that, I'm just using iconImage.setVisibility( GONE )
and iconImage.setVisibility( VISIBLE )
.
由于我堵 requestLayout
,这似乎是 setVisibility()
无法正常工作。
Since I'm blocking requestLayout
, it seems to be setVisibility()
does not work properly.
如果我用 requestLayout
,所有的树将测量和布局本身,它不是一个滚动的用户体验的好方法。
If I use requestLayout
, all the tree will measure and layout itself, and it's not a good way for a scrolling user experience.
有没有办法对回收子项目唯一的要求布局?
Is there a way for only request layout on recycle child item ?
推荐答案
您需要通知您的ListView与改变视图,以便调用 notifyDataSetChanged();
从Uithread这样的
You need to notify your listView with changed of view so call notifyDataSetChanged();
from Uithread like this :
final ArrayAdapter adapter = ((ArrayAdapter) getListAdapter());
runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
这篇关于仅重新布局的儿童,而不是所有的树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!