まず、カードゲームの画像を表すCardというオブジェクトを作成しました。
次に、Vector of Cardを受け取り、スクリーンに画像を描画する関数を作成しました。ImageViewのonCLickListenerが遅いです
ここでは、2つのシナリオについて説明します.1つは速く、もう1つは遅くなります。私はカードのベクトルを作成するとき
、私は新しいカードを作成し、このようなもので、ベクトル1に追加します。
vect.add(new Card(1, '\u2660'));
vect.add(new Card(2, '\u2660'));
vect.add(new Card(3, '\u2660'));
vect.add(new Card(8, '\u2660'));
vect.add(new Card(9, '\u2660'));
drawCards(vect);
そのように、すべてが高速に動作します。私が使用する2番目のシナリオでは、
:
私はコード内の別の場所に作成された別のカードのベクトルを持っています。そのベクターを私のdrawCards()関数に送ります。しかしそれはゆっくりと働く。
drawCards(players[0].cards);
私drawCards機能:
void drawCards(Vector<Card> myCards) {
myCardsLayout.removeAllViews();
for (Card card1 : myCards) {
final Card card = card1;
final ImageView image = new ImageView(this);
final String cardStr = card.cardToString();
Resources res = getResources();
int resID = res.getIdentifier(cardStr, "drawable", getPackageName());
image.setImageResource(resID);
image.setLayoutParams(selfLayoutParams);
image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (myTurn) {
if (currentPlayCardsVector.contains(card)) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(image.getWidth(), image.getHeight());
lp.setMargins(0, 0, 0, 0);
image.setLayoutParams(lp);
currentPlayCardsVector.remove(card);
} else {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(image.getWidth(), image.getHeight());
lp.setMargins(0, 0, 0, 20);
image.setLayoutParams(lp);
currentPlayCardsVector.add(card);
}
} else {
Toast.makeText(getApplicationContext(), "Please wait for your turn", Toast.LENGTH_SHORT).show();
}
}
});
myCardsLayout.addView(image);
}
}
私が最初に画像を描画することはOKであることを言及したいのですが、画像がクリックされたときに、応答して移動することが非常に遅いですが画像(第2のシナリオ)。
ありがとうございます。
他のベクターコードを表示し、コード内でこのvecorsを何しているのですか?私はドロー方法で何かがあると思う... –
描画方法plsを表示 –
、ありがとう – Billy