タッチイベント登録時にビューを表示したいアプリを開発中です。問題は、ビューが表示されず、コードが応答しなくなることです。
これが私の見解です:
public class TouchFX extends View {
RectF oval;
float Tx, Ty;
Paint paint;
int longSide, numRun;
float top, left, right, bottom;
boolean removable;
public TouchFX(Context context) {
super(context);
// TODO Auto-generated constructor stub
Tx = TouchService.x;
Ty = TouchService.y;
paint = new Paint();
paint.setColor(Color.WHITE);
paint.setAntiAlias(true);
paint.setStrokeJoin(Paint.Join.ROUND);
numRun = 0;
removable = false;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
if (canvas.getWidth() > canvas.getHeight())
longSide = canvas.getWidth();
else
longSide = canvas.getHeight();
if (numRun == 0) {
left = Tx - (longSide / 15);
top = Ty + (longSide / 15);
right = Tx + (longSide / 15);
bottom = Ty - (longSide / 15);
} else if (numRun <= 8) {
left += 2;
top += 2;
right += 2;
bottom += 2;
}
oval = new RectF(left, top, right, bottom);
if (numRun < 9)
canvas.drawArc(oval, 0, 360, false, paint);
else
removable = true;
numRun++;
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
これが私のonTouchハンドラーです:
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (v == tv && event.getAction() == MotionEvent.ACTION_DOWN
&& isRunning == true) {
x = event.getX();
y = event.getY();
tfx = new TouchFX(this);
winmngr.addView(tfx, lpFX);
//Do some stuff, make some Toasts
while(!tfx.removable) {
//waiting for animation to end
}
winmngr.removeView(tfx);
}
return false;
}
さて、明らかにそれはwhileループ内で立ち往生していますが、なぜそれは弧を描いてブール値を更新しないのですか?