我试图创建移动文本 。 我装箱了表面视图和环绕它的线条 。 但是它没有给我显示一个移动动作, 而是在“ 强”
但我需要的是把这一点移到 ** - & gt; ** 明白了吗? 这是我的代码 主线索package com.CurvePackage.Curve;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
public class Origin extends SurfaceView implements SurfaceHolder.Callback {
Context context1;
private MainThread thread;
private int x=0;
private int y=0;
public Origin(Context context) {
super(context);
// TODO Auto-generated constructor stub
setWillNotDraw(false);
context1 = context;
getHolder().addCallback(this);
thread = new MainThread(getHolder(), this);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Paint paint = new Paint();
paint.setTextSize(23);
paint.setFakeBoldText(true);
paint.setColor(Color.YELLOW);
// int score=(10-sprites.size()*100);
x=x+20;
y=y+20;
canvas.drawText("ewqewqe", x, y, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
return super.onTouchEvent(event);
// Toast.makeText(getba, "Replay clicked!", Toast.LENGTH_SHORT).show();
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
thread.setRunning(true);
thread.start();
}
public void surfaceDestroyed(SurfaceHolder holder) {
thread.setRunning(false);
// TODO Auto-generated method stub
// boolean retry = true;
// while (retry) {
// try {
// thread.join();
// retry = false;
// } catch (InterruptedException e) {
// // try again shutting down the thread
// }
// }
}
}
package com.CurvePackage.Curve;
import android.graphics.Canvas;
import android.view.SurfaceHolder;
public class MainThread extends Thread {
// flag to hold game state
private boolean running;
private SurfaceHolder surfaceHolder;
private Origin origin;
static final long FPS = 15;
public void setRunning(boolean running) {
this.running = running;
}
@Override
public void run() {
long ticksPS = 1000 / FPS;
long startTime;
long sleepTime;
while (running) {
Canvas c = null;
startTime = System.currentTimeMillis();
try {
c = origin.getHolder().lockCanvas();
synchronized (origin.getHolder()) {
origin.onDraw(c);
}
} finally {
if (c != null) {
origin.getHolder().unlockCanvasAndPost(c);
}
}
sleepTime = ticksPS-(System.currentTimeMillis() - startTime);
try {
if (sleepTime > 0)
sleep(sleepTime);
else
sleep(10);
} catch (Exception e) {}
}
}
public MainThread(SurfaceHolder surfaceHolder, Origin origin) {
super();
this.surfaceHolder = surfaceHolder;
this.origin = origin;
}
}
I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...