通过编程执行另一个触摸事件当一个触摸事件的Android occures [英] Programatically execute another touch event when one touch event occures in android
问题描述
我想提出的ImageView拖放与触摸原始创建重复的实例。
I am making ImageView Drag and drop with creating duplicate instance by touching original one.
我有一个水平布局containg很多小的图像。 当我触摸它会创建它的副本实例,并将在该位置在屏幕上略有不同。
I am having one horizontal-layout containg many small images. when I touch on it it creates duplicate instance of it and puts at that position on screen slight different.
现在,我要继续触摸事件,但要完成了对原有的ImageView做第一个触摸事件,并希望启动它的重复实例的触摸事件。但出除去fingure了。
Now, I want to continue the touch event but want to finish up the first one touch event done on the original ImageView and want to start-up the touch event of duplicate instance of it. but with-out removing fingure up.
我做了以下内容:
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的实例。
推荐答案
这听起来像你想要做的就是点击Image1的,有这样的行动创建一个IMAGE2,继续触摸手势,如果它被点击IMAGE2?
It sounds like what you want to do is click "Image1", have this action create an "Image2" and continue the touch gesture as if it was clicked on "Image2"?
这可能是一个更好的主意,有一个触摸表面 - 以上这些观点的捕捉触摸事件,然后分层一条无形的视图执行的操作需要 - 这将意味着你可以继续你的手势关图像而无需创建一个新的姿态。
Instead of doing this it might be a better idea to have a Touch Surface - An invisible view layered above these view's which captures the touch event and then performs the actions as needed - this will mean you can continue your gesture "off" the image without creating a new gesture.
这篇关于通过编程执行另一个触摸事件当一个触摸事件的Android occures的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!