我正在尝试做一个flipcard应用程序,其中有一个图像的gridview显示相同的图像,比如card_back。
单击每个图像时,它会翻转显示另一个图像,该图像对于gridview的每个项目都是不同的,例如card_front。
如果2张牌显示了他们的card_front图像,则1秒后自动翻转以显示card_back。
我想要做的是,在这1-2秒内,用户不应该能够点击任何其他项目。即使他点击,也不应该在那2秒内翻转卡片。如何我这样做。是否可以使用覆盖整个gridview的透明视图,并使其仅在2秒内可见。有人可以帮助我。
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
pos=position;
findViewById(R.id.view1).setBackgroundColor(getResources().getColor(android.R.color.transparent));
switch(flippedCardCounter)
{
case 0:
flippedCardCounter++; //increase counter
v1=v;
startFlipAnimation(imageView,v1);
break;
//flippedCardCounter = 1 -> one card flipped
case 1:
flippedCardCounter++; //increase counter
v2=v;
startFlipAnimation(imageView,v2);
im1=((ViewHolder) v1.getTag()).img;
im2=((ViewHolder) v2.getTag()).img;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
startUnflipAnimation(im1,v1);
startUnflipAnimation(im2,v2);
}
},1000);
break;
//flippedCardCounter = 2 -> hide two flipped card, flip one card
case 2:
flippedCardCounter = 0;
flippedCardCounter++; //increase counter
startFlipAnimation(imageView,v);
v1=v2=v;
break;
}
}
});
答案 0 :(得分:1)
也许这个帮助
public class MyClass{
....
private volatile boolean isLock=false;
gridview.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
if(isLock){return;}
pos=position;
findViewById(R.id.view1).setBackgroundColor(getResources().getColor(android.R.color.transparent));
switch(flippedCardCounter)
{
case 0:
flippedCardCounter++; //increase counter
v1=v;
startFlipAnimation(imageView,v1);
break;
//flippedCardCounter = 1 -> one card flipped
case 1:
flippedCardCounter++; //increase counter
isLock=true;
v2=v;
startFlipAnimation(imageView,v2);
im1=((ViewHolder) v1.getTag()).img;
im2=((ViewHolder) v2.getTag()).img;
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
////////////////////////
////////////////////////
startUnflipAnimation(im1,v1);
startUnflipAnimation(im2,v2);
isLock=false;
}
},1000);
break;
//flippedCardCounter = 2 -> hide two flipped card, flip one card
case 2:
flippedCardCounter = 0;
flippedCardCounter++; //increase counter
startFlipAnimation(imageView,v);
v1=v2=v;
break;
}
}
});
....
}
您可以在任意位置设置isLock
变量以禁用时钟。我希望我能伸出援助之手!