如何为ListView
中新添加的项目设置动画?
我有一个adapter
,当我在列表中添加新项时,我说adapter.notifyDataSetChanged();
项已添加,一切正常,但是我的问题是我希望新添加的元素具有一些动画。
最佳答案
Animate
在getView()
的Custom Adapter
方法中添加的每个元素。
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getActivity()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.simple_list_item_1, null);
}
ListData o = list.get(position);
TextView tt = (TextView) v.findViewById(R.id.toptext);
tt.setText(o.content);
Log.d("ListTest", "Position : "+position);
if(flag == false) {
Animation animation = AnimationUtils
.loadAnimation(getActivity(), R.anim.slide_top_to_bottom);
v.startAnimation(animation);
}
return v;
}
从而实现
Animation
。