我正在尝试做一种翻转卡应用程序,其中有显示相同图像的图像网格视图,比如 card_back。
单击每个图像时,它会翻转显示另一个图像,该图像对于 gridview 的每个项目都不同,比如 card_front。
我想要做的是,如果显示两张卡片正面,点击下一个项目,前两张卡片应该翻转以显示他们的卡片背面图像。即,一次最多只有两张卡片可以显示他们的卡片正面图像.但我不知道该怎么做。
谁能帮帮我。在此先感谢。
这是在gridview中翻转图像的代码。
public class FullscreenActivity extends Activity
implements OnItemClickListener, AnimationListener
{ ImageView imageView ;
int pos;
Animation animation1;
Animation animation2;
int[] clicked = {0,0,0,0,0,0,0,0,0,0,0,0};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fullscreen);
animation1 = AnimationUtils.loadAnimation(this, R.anim.to_middle);
animation1.setAnimationListener(this);
animation2 = AnimationUtils.loadAnimation(this, R.anim.from_middle);
animation2.setAnimationListener(this);
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
pos=position;
imageView = ((ViewHolder) v.getTag()).img;
(imageView).clearAnimation();
(imageView).setAnimation(animation1);
(imageView).startAnimation(animation1);
}
});
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
{
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation arg0) {
if (arg0==animation1) {
if(clicked[pos]==0)
{
imageView.setImageResource(ImageAdapter.mThumbSelected[pos]);
clicked[pos]=1;
} else if(clicked[pos]==1) {
clicked[pos]=0;
imageView.setImageResource(R.drawable.card_back);
}
imageView.clearAnimation();
imageView.setAnimation(animation2);
imageView.startAnimation(animation2);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}