我正在通过触摸原始实例来创建 ImageView 拖放并创建重复实例。
我有一个包含许多小图像的水平布局。当我触摸它时,它会创建它的重复实例并放在屏幕上的那个位置略有不同。
现在,我想继续触摸事件,但想完成在原始 ImageView 上完成的第一个触摸事件,并希望启动它的重复实例的触摸事件。但无需移除手指。
我做了以下工作:
img22.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
ImageView img2 = null;
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN :
... ...
... ...
Bitmap bmp2 = BitmapFactory.decodeResource(ImageListActivity.this.getResources(),
R.drawable.img2);
//ImageView
img2 = new ImageView(ImageListActivity.this);
img2.setImageBitmap(bmp2);
img2Param.setMargins( (rx-10-x), (ry-10-y-50), 0, 0);
img2.setLayoutParams(img2Param);
img2.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println(" --- img2 On Touch Called ---");
RelativeLayout.LayoutParams img2Param =
(RelativeLayout.LayoutParams) v.getLayoutParams();
img2Param.setMargins((int)event.getRawX()-10, (int)event.getRawY()-60, 0, 0);
v.setLayoutParams(img2Param);
v.invalidate();
return true;
}
});
long downTime2 = SystemClock.currentThreadTimeMillis(),
eventTime2 = SystemClock.currentThreadTimeMillis() + 10;
float x2 = 0.0f, y2 = 0.0f;
int metaState2 = 0;
MotionEvent motionEvent2 = MotionEvent.obtain(
downTime2, eventTime2, MotionEvent.ACTION_POINTER_1_UP, x2, y2, 1);
v.dispatchTouchEvent(motionEvent2);
long downTime = SystemClock.currentThreadTimeMillis(),
eventTime = SystemClock.currentThreadTimeMillis();// + 5000;
float x1 = 0.0f, y1 = 0.0f;
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime, eventTime, MotionEvent.ACTION_MOVE, x1, y1, 1);
img2.onTouchEvent(motionEvent);
... ...
... ...
谁能给我关于继续触摸事件和更改 ImageView 实例的想法。