我有简单的ListView,它显示数据库中的数据。每隔1分钟后,数据会自动刷新。以下是我用来执行此操作的代码段:
DataAdapter adp = (DataAdapter) DataList.getAdapter();
adp.UpdateDataList(DataAdapter.DATA_LIST);
adp.notifyDataSetChanged();
DataList.invalidateViews();
DataList.scrollBy(0, 0);
我创建了ListView,即DataView和dataAdapter,只是扩展了baseAdapter。 UpdateDataList只是从数据库中获取数据并创建一个arrayList。 并且适配器通知视图刷新数据。
一切都很完美。 现在我要做的一件事就是当数据刷新时我需要添加某种动画以使其成为眼睛缓存。人们会说出事情发生了。
与iPhone应用程序类似。我不想添加微调器,因为数据更新是同步过程,所以数据更改很快就不会在视图中进行任何新的更改。简单的数字被翻转了。
任何帮助将不胜感激....
答案 0 :(得分:10)
这是我尝试过的代码并且对我有用....
/* Setting up Animation */
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(400);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(400);
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.25f);
parent.setLayoutAnimation(controller);
/* Animation code ends */
答案 1 :(得分:1)
也许你可以将动画附加到ListView,因为ListView扩展了ViewGroup你可以做到,阅读android参考上的LayoutAnimationController:http://developer.android.com/reference/android/view/animation/LayoutAnimationController.html
欢呼声