Nav*_*deh 7 animation android listview android-listview
我有一个listView,大约有20个项目(动态项目).我想先向用户展示这些项目的动画.像Google+卡片.我想要实现一些要点:
到目前为止,我尝试过:
我搜索了很多但是没有找到解决方案.
顺便说一句,我不想使用外部库.我之前见过这个.
谢谢.
我刚试过这个,似乎满足了你的所有要求:
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;
}
Run Code Online (Sandbox Code Playgroud)
如果您有兴趣,这是我的fade_in.xml文件:
<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>
Run Code Online (Sandbox Code Playgroud)