さまざまな画像を移動する必要がある Android アプリケーションを実行しています。いくつかのコーディングを行いましたが、問題は次のとおりです。1つの画像を移動したいときに、他の画像がそれに続きます。ビットマップ上の画像ごとに異なるオンタッチリスナーを作成することは可能ですか??
MyBringBackSurface ourSurfaceView, ourSurfaceView2;
float x, y, sX, sY, fX, fY, dX, dY, aniX, aniY, scaledX, scaledY;
Bitmap test;
Bitmap dress, dress2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
ourSurfaceView = new MyBringBackSurface(this);
ourSurfaceView.setOnTouchListener(this);
x = 0;
y = 0;
sX = 0;
sY = 0;
fX = 0;
fY = 0;
dX = dY = aniX = aniY = scaledX = scaledY = 0;
dress = BitmapFactory.decodeResource(getResources(), R.drawable.dress);
dress2 = BitmapFactory
.decodeResource(getResources(), R.drawable.dress2);
test = BitmapFactory.decodeResource(getResources(),
R.drawable.cinderelladoll);
setContentView(ourSurfaceView);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSurfaceView.pause();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
ourSurfaceView.resume();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
x = event.getX();
y = event.getY();
sX = event.getX();
sY = event.getY();
return true;
}
public class MyBringBackSurface extends SurfaceView implements Runnable {
SurfaceHolder ourHolder;
Thread ourThread = null;
boolean isRunning = false;
Bitmap back;
public MyBringBackSurface(Context context) {
super(context);
ourHolder = getHolder();
back = BitmapFactory.decodeResource(getResources(),
R.drawable.wallpaper);
}
public void pause() {
isRunning = false;
while (true) {
try {
ourThread.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
ourThread = null;
}
public void resume() {
isRunning = true;
ourThread = new Thread(this);
ourThread.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
while (isRunning) {
if (!ourHolder.getSurface().isValid())
continue;
Canvas canvas = ourHolder.lockCanvas();
canvas.drawRGB(02, 02, 150);
canvas.drawBitmap(back, 0, 0, null);
if (x != 0 && y != 0) {
canvas.drawBitmap(test, 150, 150, null);
canvas.drawBitmap(dress2, x - (dress2.getWidth() / 2), y
- (dress2.getHeight() / 2), null);
canvas.drawBitmap(dress, x - (dress.getWidth() / 2), y
- (dress.getHeight() / 2), null);
}
ourHolder.unlockCanvasAndPost(canvas);
}
}
}
}