我有这个问题:
我有ImageView
,我在onTouchListener
设置了它,我可以移动它。
问题是我想设置相同的imageview来收听DoubleClick事件。
您是否有任何可以帮助我解决此问题的示例?
我需要移动并双击相同的imageview!
答案 0 :(得分:0)
public class Touch_Screen extends Activity implements OnTouchListener {
private ImageView mImageView;
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.touch_test);
super.onCreate(savedInstanceState);
mRrootLayout = (ViewGroup) findViewById(R.id.root);
mImageView = (ImageView) mRrootLayout.findViewById(R.id.imageView);
mImageView.setVisibility(View.INVISIBLE);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(150, 150);
mImageView.setLayoutParams(layoutParams);
mImageView.setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
try {
Thread.sleep(50);
} catch (Exception e) {
// TODO: handle exception
}
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
_xDelta = X - lParams.leftMargin;
_yDelta = Y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_POINTER_DOWN:
break;
case MotionEvent.ACTION_POINTER_UP:
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
layoutParams.leftMargin = X - _xDelta;
layoutParams.topMargin = Y - _yDelta;
layoutParams.rightMargin = -250;
layoutParams.bottomMargin = -250;
view.setLayoutParams(layoutParams);
break;
}
mRrootLayout.invalidate();
return true;
}
}