1
這是我的全部代碼移動位圖中,,,,如何通過一個
有人能幫助我,,,
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(new Panel(this));
}
}
class Panel extends SurfaceView implements SurfaceHolder.Callback {
private Bitmap[] mBitmap;
private ViewThread mThread;
public Panel(Context context) {
super(context);
mBitmap = new Bitmap[4];
mBitmap[0] = BitmapFactory.decodeResource(getResources(), R.drawable.x);
mBitmap[1] = BitmapFactory.decodeResource(getResources(), R.drawable.x);
mBitmap[2] = BitmapFactory.decodeResource(getResources(), R.drawable.x);
mBitmap[3] = BitmapFactory.decodeResource(getResources(), R.drawable.x);
getHolder().addCallback(this);
mThread = new ViewThread(this);
}
public void doDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(mBitmap[0], 0, 0, null);
canvas.drawBitmap(mBitmap[1], 45, 0, null);
canvas.drawBitmap(mBitmap[2], 90, 0, null);
canvas.drawBitmap(mBitmap[3], 135, 0, null);
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (!mThread.isAlive()) {
mThread = new ViewThread(this);
mThread.setRunning(true);
mThread.start();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (mThread.isAlive()) {
mThread.setRunning(false);
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mX = (int) event.getX() - mBitmap[0].getWidth()/2;
mX = (int) event.getX() - mBitmap[1].getWidth()/2;
mX = (int) event.getX() - mBitmap[2].getWidth()/2;
mX = (int) event.getX() - mBitmap[3].getWidth()/2;
return super.onTouchEvent(event);
}
class ViewThread extends Thread {
private Panel mPanel;
private SurfaceHolder mHolder;
private boolean mRun = false;
public ViewThread(Panel panel) {
mPanel = panel;
mHolder = mPanel.getHolder();
}
public void setRunning(boolean run) {
mRun = run;
}
@Override
public void run() {
Canvas canvas = null;
while (mRun) {
canvas = mHolder.lockCanvas();
if (canvas != null) {
mPanel.doDraw(canvas);
mHolder.unlockCanvasAndPost(canvas);
}
}
}
}
如何移動的位圖到右,由一個位圖我留一個
如果位圖移動則位圖什麼是錯在我的代碼毗鄰
?
如何解決這個我的代碼?
請幫我