我为正在处理的Blackjack应用程序编写了以下方法。
public void showCard(View view){
startButton.setVisibility(View.INVISIBLE);
hitButton.setVisibility(View.VISIBLE);
standbutton.setVisibility(View.VISIBLE);
Card dealtCardOnePlayer = deck.dealACard();
Card dealtCardOneDealer = deck.dealACard();
Card dealtCardTwoPlayer = deck.dealACard();
Card dealtCardTwoDealer = deck.dealACard();
player.getCardsInHand().add(dealtCardOnePlayer);
dealer.getCardsInHand().add(dealtCardOneDealer);
player.getCardsInHand().add(dealtCardTwoPlayer);
dealer.getCardsInHand().add(dealtCardTwoDealer);
playerCardOne.setImageResource(dealtCardOnePlayer.getCardImagePath());
dealerCardOne.setImageResource(dealtCardOneDealer.getCardImagePath());
playerCardTwo.setImageResource(dealtCardTwoPlayer.getCardImagePath());
dealerCardTwo.setImageResource(R.drawable.back);
}
它基本上会向玩家和经销商发放前两张牌。最后四行代码将图像资源设置为ImageViews。我想在前一个图像资源之后设置一秒钟。我如何实现这一目标?
答案 0 :(得分:0)
您可以将Handler
的{{1}}方法用于延迟特定代码:
postDelayed()
静:
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//execute code here after 1000 milliseconds
}
}, 1000);
答案 1 :(得分:-1)
您可以尝试在行之间放置:
Thread.sleep(1000);
这将在每次更新图像视图后停止执行一秒钟。