我想在拖动图像向左拖动时将拖动图像颜色的边框更改为红色,如果向右拖动则将蓝色更改为蓝色。不是拖后但是在拖动时。这可能吗?我正在谈论的是在拖动时更改DragShadowBuilder图像。我有这段代码:
drop.setOnDragListener(new View.OnDragListener() {
@Override
public boolean onDrag(View v, DragEvent event) {
Float y1 = event.getX();
Float x1 = event.getY();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// Do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
x1 = event.getX();
y1 = event.getY();
break;
case DragEvent.ACTION_DRAG_EXITED:
Log.d("msg", "Action is DragEvent.ACTION_DRAG_EXITED");
cView.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_LOCATION:
Float x2 = event.getX();
Float y2 = event.getY();
if (x2 > x1) {
cView.setBorderColor(Integer.parseInt("2E4172", 16) + 0xFF000000);
cView.setShadowColor(Integer.parseInt("4F628E", 16) + 0xFF000000);
} else {
cView.setBorderColor(Integer.parseInt("AA3939", 16) + 0xFF000000);
cView.setShadowColor(Integer.parseInt("D46A6A", 16) + 0xFF000000);
}
break;
case DragEvent.ACTION_DRAG_ENDED:
// Do nothing
cView.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DROP:
// Do nothing
Log.d("Drop Location", Float.toString(event.getX()) + " : " + Float.toString(event.getY()));
cView.setVisibility(View.VISIBLE);
String direction = new String();
x2 = event.getX();
y2 = event.getY();
if (x2 > x1) {
direction = "right";
} else {
direction = "left";
}
Log.d("Going to Directon", direction);
break;
default:
break;
}
return true;
}
});
cView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d("Motion Action", event.toString());
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: {
// store the X value when the user's finger was pressed down
ClipData data = ClipData.newPlainText("", "");
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(cView);
cView.startDrag(data, shadowBuilder, cView, 0);
cView.setVisibility(View.INVISIBLE);
return true;
}
case MotionEvent.ACTION_MOVE: {
}
}
return true;
}
});