0

我正在尝试做一个翻转卡应用程序,其中有显示相同图像的图像网格视图,比如 card_back。

单击每个图像时,它会翻转显示另一个图像,该图像对于 gridview 的每个项目都不同,比如 card_front。

如果 2 张卡片正在显示其 card_front 图像,则在 1 秒后两者都会自动翻转以显示 card_back。

我想要做的是在这 1-2 秒内,用户不应该能够点击任何其他项目。或者即使他点击,在这 2 秒内也不应该翻转卡片。我该怎么做.是否可以使用覆盖整个网格视图的透明视图并使其仅在 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;
            }
                 }

              }); 
4

1 回答 1

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任何您喜欢禁用时钟的地方设置变量。我希望我能伸出援手!

于 2013-10-13T14:05:33.770 回答