private Bitmap[] bmp = new Bitmap[10];//ビットマップ private int keta[]={0,1,2,3}; // x座標の画像位置 private boolean up1 = false; // 2桁目の数字をカウント private boolean up2 = false; // 3桁目の数字をカウント private boolean up3 = false; // 4桁目の数字をカウント private boolean up4 = false; // 9999の数字をカウント private int caunt1=0; // 画像表示 private int caunt2=0; // 画像表示 private int caunt3=0; // 画像表示 private int caunt4=0; // 画像表示 private int flag; // 画像の描画 for(int i = 0; i < 4; i++) { canvas.drawBitmap(bmp[0], keta[i]*70, 0, null); } if(caunt1>0 && caunt1<10){ canvas.drawBitmap(bmp[caunt1], keta[3]*70, 0, null); } if(caunt2>0 && caunt2<10){ canvas.drawBitmap(bmp[caunt2], keta[2]*70, 0, null); } if(caunt3>0 && caunt3<10){ canvas.drawBitmap(bmp[caunt3], keta[1]*70, 0, null); } if(caunt4>0 && caunt4<10){ canvas.drawBitmap(bmp[caunt4], keta[0]*70, 0, null); } if(up4){ canvas.drawBitmap(bmp[9], keta[0]*70, 0, null); canvas.drawBitmap(bmp[9], keta[1]*70, 0, null); canvas.drawBitmap(bmp[9], keta[2]*70, 0, null); canvas.drawBitmap(bmp[9], keta[3]*70, 0, null); } Paint paint = new Paint(); switch ((int)flag) { case 1: //カウント if(caunt1 > 9){ caunt1=0; up1 = true; } if(up1){ caunt2+=1; up1=false; if(caunt2 > 9){ caunt2=0; up2=true; } } if(up2){ caunt3+=1; up2=false; if(caunt3 > 9){ caunt3=0; up3=true; } } if(up3){ caunt4+=1; up3=false; if(caunt4 > 9){ up4=true; } } if(caunt1>0 && caunt1<10){ canvas.drawBitmap(bmp[caunt1], keta[3]*70, 0, null); } if(caunt2>0 && caunt2<10){ canvas.drawBitmap(bmp[caunt2], keta[2]*70, 0, null); } if(caunt3>0 && caunt3<10){ canvas.drawBitmap(bmp[caunt3], keta[1]*70, 0, null); } if(caunt4>0 && caunt4<10){ canvas.drawBitmap(bmp[caunt4], keta[0]*70, 0, null); } if(up4){ canvas.drawBitmap(bmp[9], keta[0]*70, 0, null); canvas.drawBitmap(bmp[9], keta[1]*70, 0, null); canvas.drawBitmap(bmp[9], keta[2]*70, 0, null); canvas.drawBitmap(bmp[9], keta[3]*70, 0, null); } break; } // 現在の状態の変更 canvas.restore(); } // ボタンを押してをカウント描画 public void blue() { caunt1+=1; if(caunt1 > 9){ caunt1=0; up1 = true; } if(up1){ caunt2+=1; up1=false; if(caunt2 > 9){ caunt2=0; up2=true; } } if(up2){ caunt3+=1; up2=false; if(caunt3 > 9){ caunt3=0; up3=true; } } if(up3){ caunt4+=1; up3=false; if(caunt4 > 9){ up4=true; } } flag=1; } //ビットマップの読み込み private static Bitmap readBitmap(Context context, String name) { int resID = context.getResources().getIdentifier( name, "drawable", context.getPackageName()); return BitmapFactory.decodeResource( context.getResources(), resID); } }
【訂正】
すみません、コードの一番上に変数を記入しました。
Bitmapで0~9の画像を入れてます。
// ボタンを押してをカウント描画のところでcaunt1+=1で増やしてflagでswitch文のcaseの//カウントで数字を増やしています。
一桁の数字が9以上になったらup1をtrueにして二桁目をカウントする感じにしています。
説明不足ですみません。また足りないところがあったら指摘してください。
上のプログラミングは一部抜粋ですが、ボタンを押すと1ずつ数字の画像が増えます。最大で9999カウントできます。
でもプログラミング長くなってしまったので、もっと簡単なやり方があったら教えてください。
あと、数字のカウントを15ずつカウントするにはどうしたらよいでしょうか?このやり方だと1つずつのカウントしかできません。
回答3件
あなたの回答
tips
プレビュー