动画的ListView孩子的唯一一次出现 [英] animate listView childs only once they appear
本文介绍了动画的ListView孩子的唯一一次出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有大约20个项目(动态项目)列表视图。我想他们首先出现用户动画这些项目。类似Google+的卡。有一些点,我想实现:
I have a listView with about 20 items (dynamic items). I want to animate these items first they show up to user. something like Google+ cards. There are some points that I want to achieve:
- 在项目仅当用户开始看到他们的动画。
- 动画项目只有一次。 (不是每次用户看到他们)
- 在快速滚动的物品千万不要乱了对方。
- 动画根据项位置开始的延迟。
到现在为止我已经尝试:
Up to now I have tried:
- LayoutAnimationController(这种方法不符合第一个要求)
- convertView.startAnimation(这种方法不符合第二个要求)
- convertView.startAnimation用,如果在位置,这个项目一直动画之前或没有(这个方法并没有在ListView中的第一项,因为,在getView方法将被用于在ListView中第一项调用两次合作的标志。(我不知道为什么!layout_height和layout_width都是match_parent))
我搜索了很多,但不能同时解决办法来。
I searched a lot but couldn't come along with a solution.
顺便说一句,我preFER不使用外部库。我见过这之前。
By the way, I prefer not to use external libraries. I have seen this before.
感谢。
推荐答案
我只是尝试这样做,它似乎以满足您的所有需求:
I've just tried this and it seems to meet all of your requirements:
boolean[] animationStates;
public void YourConstructor(...) {
...
animationStates = new boolean[data.size()];
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// (Re)Use the convertView
if (convertView == null) {
convertView = mInflater.inflate(R.layout.popup_list_item, parent, false);
if (!animationStates[position]) {
Log.e("TAG", "Animating item no: " + position);
animationStates[position] = true;
Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.fade_in);
animation.setStartOffset(position*500);
convertView.startAnimation(animation);
}
}
// Use convertView here
return convertView;
}
下面是我的fade_in.xml文件,如果你有兴趣:
Here's my fade_in.xml file if you're interested:
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha
android:duration="1000"
android:fromAlpha="0.0"
android:toAlpha="1.0"/>
</set>
这篇关于动画的ListView孩子的唯一一次出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文