|
|
|
Android ไว้แสดงภาพซัก 1 - 2 วินาที เขียนอย่างไรบ้างคะ |
|
|
|
|
|
|
|
เอา Code บางส่วนมาให้ดูคะ
Code (Android-Java)
public boolean onTouchEvent(MotionEvent event) {
int eventaction = event.getAction();
int X = (int)event.getX();
int Y = (int)event.getY();
switch (eventaction ) {
case MotionEvent.ACTION_DOWN: // touch down so check if the finger is on a ball
object_id = -1;
for(int i = 0 ; i < object.length ; i++) {
double radCircle = Math.sqrt( Math.pow(Math.abs(X - object_position[i][0]), 2)
+ Math.pow(Math.abs(Y - object_position[i][1]), 2) );
if(radCircle < bm[i].getWidth() / 2 && !goal[i]) {
object_id = i;
}
}
case MotionEvent.ACTION_MOVE:
if(object_id != -1 && !goal[object_id] ) {
object_position[object_id][0] = X;
object_position[object_id][1] = Y;
}
break;
case MotionEvent.ACTION_UP:
if(object_id != -1 && !goal[object_id] ) {
double radCircle = Math.sqrt( Math.pow(Math.abs(object_position[object_id][0] - goal_position[0]), 2)
+ Math.pow(Math.abs(object_position[object_id][1] - goal_position[1]), 2) );
Log.i("Check", String.valueOf(radCircle));
Log.i("CalCheck", String.valueOf(Math.abs(goal_radius - (bm[object_id].getHeight() / 2))));
if(radCircle <= Math.abs(goal_radius)) {
if(object_id == object_count)
{
goal[object_id] = true;
// score++;
object_count++;
MediaPlayer play = MediaPlayer.create(getContext(),R.raw.to);//เสียงถูกต้องนะครับ
play.start();
this.setBackgroundResource(R.drawable.fa3); // ////////เมื่อถูกก็แสดงเปลี่ยนภาพพื้นหลัง แต่ทีนี้ต้องการว่าหากอยากให้แสดงภาพแค่ 1-2 วินาที แล้วกลับไปใช้ภาพพื้นหลังเดิมต้องเขียนยังไงคะ//////
if(object_count == object.length)
{
Intent intent = new Intent(mContext,Finish.class);
mContext.startActivity(intent);
System.exit(0);
}
}
else
{
object_position[object_id][0] = object_default_position[object_id][0];
object_position[object_id][1] = object_default_position[object_id][1];
MediaPlayer play = MediaPlayer.create(getContext(), R.raw.pe);//เสียงไม่ถูกต้องนะครับ
play.start();
}
}
}
break;
}
invalidate();
return true;
}
ตามที่เมคไว้ข้างบนเลยคะ
ปกติตามเงื่อนไขแล้วเมื่อถูกก็แสดงเปลี่ยนภาพพื้นหลัง แต่ทีนี้ต้องการว่าหากอยากให้แสดงภาพแค่ 1-2 วินาที แล้วกลับไปใช้ภาพพื้นหลังเดิมต้องเขียนยังไงคะ
Tag : Mobile, Android
|
|
|
|
|
|
Date :
2013-02-27 20:26:32 |
By :
may |
View :
931 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมดูแล้วไม่ยากนิดหนึ่งน่ะครับ แต่ถ้าห่วงเวลาของดูพวก Timer + Thread ครับ
|
|
|
|
|
Date :
2013-02-28 09:47:35 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|