0

我正在为 GridView 使用自定义适配器,并为其提供自定义数据类的 ArrayList。

这个想法是,当用户在一个项目上按下 (+) 时,它的数字会上升,当他们按下 (-) 时,它就会下降。

这与以下代码完美配合:

活动:

//playerLayouts is the ArrayList of my Player class.
playerLayouts.get(position).changeLife(-1); //All this does is decrement life by 1.
adapter.notifyDataSetChanged();

适配器:

holder.textLife = (TextView) row.findViewById(R.id.player.text_life);
...
holder.textLife.setText(Integer.toString(player.life));

所以这很好用。我按加号,它上升,我按减号,它下降。一切都很好。

但是,如果我想在视图中放一个小“-1”弹出窗口,显示已减去 1,并且我为视图设置动画,就会出现问题。

...
//textLifeChange is a different TextView in the layout. Also, I'm using NineOldAndroids.
textLifeChange.setText(Integer.toString(player.lifeChange));
animate(holder.textLifeChange).setDuration(2000).alpha(0); //There are a few more animations in addition to this one.

基本上,无论何时播放动画(整整两秒),视图都不再进行更新。

例如,说“生命”= 20。我按 (-),现在它显示 19,我的小弹出窗口显示“-1”并淡出。然后,仅仅一秒钟后,我再次击中(-1)。没发生什么事。“生活” TextView 仍然显示 19,并且弹出窗口只是继续播放其动画,没有任何变化。所以我再等一秒钟,动画就完成了。现在,如果我再次按 (-),它会再次正确更新。

有趣的是,如果我记录我的setText方法,我会看到它正在使用正确的数字进行更新,并且getView正在被调用,但它只是......没有明显更新。

怎么了?

4

1 回答 1

1

我敢说您的动画占用了 UI 线程,因此阻止了界面其他部分的更改。这个答案应该可以帮助您:

Android:运行线程阻止动画启动

于 2012-12-21T13:57:20.720 回答