在iOS中,有一个非常简单和强大的工具来动画添加和删除UITableView行,这是一个来自youtube视频的剪辑,显示默认动画。注意周围的行如何折叠到已删除的行上。这个动画帮助用户跟踪列表中发生了什么变化,以及当数据发生变化时他们正在查看列表中的哪个位置。
Since I've been developing on Android I've found no equivalent facility to animate individual rows in a TableView. Calling notifyDataSetChanged() on my Adapter causes the ListView to immediately update its content with new information. I'd like to show a simple animation of a new row pushing in or sliding out when the data changes, but I can't find any documented way to do this. It looks like LayoutAnimationController might hold a key to getting this to work, but when I set a LayoutAnimationController on my ListView (similar to ApiDemo's LayoutAnimation2) and remove elements from my adapter after the list has displayed, the elements disappear immediately instead of getting animated out.
我还尝试了如下方法,在移除单个项目时将其动画化:
@Override
protected void onListItemClick(ListView l, View v, final int position, long id) {
Animation animation = new ScaleAnimation(1, 1, 1, 0);
animation.setDuration(100);
getListView().getChildAt(position).startAnimation(animation);
l.postDelayed(new Runnable() {
public void run() {
mStringList.remove(position);
mAdapter.notifyDataSetChanged();
}
}, 100);
}
但是,动画行周围的行不会移动位置,直到调用notifyDataSetChanged()时它们跳转到新位置。一旦元素被放置,ListView似乎不会更新它的布局。
虽然写我自己的ListView的实现/分支已经越过我的脑海,这似乎不应该是那么困难的事情。
谢谢!