这是我的要求。从Web服务向网格视图添加内容,并随机将淡入动画应用于每个网格项。只有一个网格项将被动画化。
这是我的XML代码,
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="1000"
android:repeatCount="1"
/>
</set>
我在这里调用动画:
Runnable runnable = new Runnable() {
@Override
public void run() {
/* do what you need to do */
s=RandonNumberGenerator.randInt(0, arg0.getResult1().size()-1);
flipCard(s);
/* and here comes the "trick" */
handler.postDelayed(this,1000);
}
};
handler.postDelayed(runnable, 1000);
我将随机生成的网格项索引传递给我的方法。
public void flipCard(int x)
{
zoomin.setAnimationListener((AnimationListener) this);
View viewItem = dashboardgv.getChildAt(x);
if (viewItem != null) {
ImageView img = (ImageView) viewItem.findViewById(R.id.db_image);
s=x;
TextView overlay=(TextView) viewItem.findViewById(R.id.overlayText);
overlay.setVisibility(View.VISIBLE);
overlay.setAnimation(zoomin);
overlay.startAnimation(zoomin);
zoomin.setRepeatCount(0);
// overlay.setVisibility(View.GONE);
}
}
这是我的动画监听器:
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
animation.cancel();
// TODO Auto-generated method stub
// zoomin.setAnimationListener((AnimationListener) this);
View viewItem = dashboardgv.getChildAt(s);
if (viewItem != null) {
ImageView img = (ImageView) viewItem.findViewById(R.id.db_image);
img.setAnimation(zoomout);
TextView overlay=(TextView) viewItem.findViewById(R.id.overlayText);
overlay.setVisibility(View.GONE);
overlay.setAnimation(zoomout);
img.startAnimation(zoomout);
overlay.startAnimation(zoomout);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
animation.cancel();
}
现在,它永远重复动画。例如,如果我有四个网格项,每个网格项中的淡入动画将永远重复。