我正在开发一款卡片游戏。我有一个gridview,每个网格项都是一个viewflipper。每个ViewFlipper都有一个textview和一个imageview。单击项目会从textview翻转到3D动画中的imageview。我想在viewflipper的动画结束后开始另一个项目的动画。(注意:我在适配器类的viewflipper上添加了点击监听器)
这里是适配器代码:
public class MyGridViewAdapter extends BaseAdapter {
int[]icons;
Context context;
int counter;
View view = null;
GridView grid;
HashMap<String,View> hashMap;
public MyGridViewAdapter(int[] icons,Context context,GridView grid) {
// TODO Auto-generated constructor stub
this.icons=icons;
this.context=context;
this.grid=grid;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return icons.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return icons[arg0];
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(final int arg0, final View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
hashMap=new HashMap<String,View>();
LayoutInflater layoutInflater=(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ViewHolder viewHolder=new ViewHolder();
if(arg1==null){
view=new View(context);
view=layoutInflater.inflate(R.layout.view_flipper, null);
viewHolder.text=(TextView)view.findViewById(R.id.name);
viewHolder.image=(ImageView)view.findViewById(R.id.picture);
viewHolder.image.setImageResource(icons[arg0]);
}else{
view=(View)arg1;
}
final ViewFlipper flipper = (ViewFlipper)view.findViewById(R.id.my_view_flipper);
flipper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
// TODO Auto-generated method stub
AnimationFactory.flipTransition(flipper, FlipDirection.LEFT_RIGHT,300);
Animation animation=flipper.getInAnimation();
animation.setAnimationListener(new AnimationListener() {
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
flipper.setEnabled(false);
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
counter++;
hashMap.put(""+counter, v);
flipper.setEnabled(true);
Log.i("counter", ""+counter);
AnimationFactory.flipTransition(flipper, FlipDirection.RIGHT_LEFT, 250);
}
});
}
});
return view;
}
public class ViewHolder{
private TextView text;
private ImageView image;
}
}