【发布时间】:2018-05-24 09:23:59
【问题描述】:
我需要帮助,通过将苹果放在桶图像中,在 android 中用苹果填充篮子的动画。下面是我的拖放代码,我将苹果从一个地方拖放到另一个地方。
@Override
public boolean onDrag(View v, DragEvent event) {
// Store the action type for the incoming event
final int action = event.getAction();
// Handles each of the expected events
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
// Invalidate the view to force a redraw in the new tint
v.invalidate();
// Returns true to indicate that the View can accept the
// dragged data.
return true;
case DragEvent.ACTION_DRAG_ENTERED:
v.invalidate();
return true;
case DragEvent.ACTION_DRAG_LOCATION:
// Ignore the event
return true;
case DragEvent.ACTION_DRAG_EXITED:
v.invalidate();
return true;
case DragEvent.ACTION_DROP:
v.invalidate();
if (v instanceof ImageView) {
ImageView dropView = (ImageView) v;
Drawable dropViewDrawable = dropView.getDrawable();
Log.v("dropViewDrawable", "" + dropViewDrawable);
for (int i = 0; i < numberOfObject; i++) {
if (containerImageViewList.get(i).getDrawable() == null) {
containerImageViewList.get(i).setImageResource(R.drawable.sp_glass_cut);
if (selectedImageColor.equals(getResources().getString(R.string.title_images_color_grey))) {
containerImageViewList.get(i).setImageBitmap(CommonMethods.convertColoredImageIntoBlackAndWhiteImage(containerImageViewList.get(i)));
}
break;
}
}
dragImageView.setImageBitmap(null);
successCount++;
} else {
CommonMethods.showSweetAlertDialog(SPLevelOneMoveObjectTBActivity.this, false);
}
return true;
case DragEvent.ACTION_DRAG_ENDED:
v.invalidate();
Log.v("ACTION_DRAG_ENDED", "ACTION_DRAG_ENDED");
if (!isSuccess && !isFail) {
isFail = true;
CommonMethods.showSweetAlertDialog(SPLevelOneMoveObjectTBActivity.this, false);
return true;
}
return true;
default:
break;
}
return false;
}
现在如何制作动画并显示篮子里的苹果?
【问题讨论】:
标签: java android android-studio