我有六个图像视图和文本视图。
它们最初是隐藏的(android:visibility="gone"
)。
我将它们存储在两个数组中:arr_image_views
和arr_text_views
。
我想分别展示它们。
我制作了一个FadeAnimationClass类。
private class FadeAnimationClass implements AnimationListener{
private TextView txtview;
private ImageView imageview ;
public FadeAnimationClass(TextView t , ImageView i){
this.txtview = t ;
this.imageview = i ;
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
txtview.setVisibility(View.VISIBLE);
imageview.setVisibility(View.VISIBLE);
}
}
animFadeOut = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out);
animFadeIn = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in);
current_cat = "1";
arr_cat.add("1");
arr_cat.add("2");
arr_cat.add("3");
arr_cat.add("4");
arr_cat.add("5");
arr_cat.add("6");
现在,我想分别开始动画:
for(int i=0 ; i <arr_image_views.size() ; ++i){
if(current_cat.equalsIgnoreCase(arr_cat.get(i))){
animFadeIn.setAnimationListener(new FadeAnimationClass(arr_text_views.get(i),arr_image_views.get(i)));
animFadeIn.setDuration(2000);
arr_image_views.get(i).setAnimation(animFadeIn);
arr_text_views.get(i).setAnimation(animFadeIn);
animFadeIn.start();
arr_image_views.remove(arr_image_views.get(i));
arr_text_views.remove(arr_text_views.get(i));
for(int j=0 ; j <arr_image_views.size() ; ++j){
animFadeIn.setAnimationListener(new FadeAnimationClass(arr_text_views.get(j),arr_image_views.get(j)));
animFadeIn.setDuration(4000);
arr_image_views.get(j).setAnimation(animFadeIn);
arr_text_views.get(j).setAnimation(animFadeIn);
animFadeIn.start();
}
break ;
}
}
但上面的代码显示了图片视图和文本视图!