我正在尝试使用触摸视图事件实现自己的拖放。我希望通过长按来触发拖动,在onLongClick中,我创建了一个视图阴影作为位图,并将此位图设置为imageview。我想拖动这个imageview。我的问题是,长按事件后,imageview不能立即响应触摸事件。我必须停止触摸屏幕并再次点击imageview,然后我的图像才会移动。
一些相关代码:
mCategoryNews.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
v.setVisibility(View.INVISIBLE);
ImageView shadow = (ImageView) getView().findViewById(R.id.imgViewShadow);
shadow.setLayoutParams(new FrameLayout.LayoutParams(v.getWidth(), v.getHeight()));
shadow.setImageBitmap(Utils.loadBitmapFromView(v));
shadow.bringToFront();
((FrameLayout.LayoutParams) shadow.getLayoutParams()).leftMargin = rowCategories1.getLeft();
((FrameLayout.LayoutParams) shadow.getLayoutParams()).topMargin = rowCategories1.getTop();
return true;
}
});
private View.OnTouchListener mDragShadowTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(TAG, "onTouch");
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
Log.d(TAG, "action move");
int x = (int) event.getRawX();//- rowCategories1.getLeft() - v.getWidth() / 2;
int y = (int) event.getRawY();//- rowCategories1.getTop() - v.getHeight();
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(mRowWidth / 2, mRowHeight);
params.setMargins(x, y, 0, 0);
v.setLayoutParams(params);
break;
case MotionEvent.ACTION_DOWN:
break;
}
return true;
}
};
长时间按住屏幕后,没有任何日志输出。