Android:将可拖动的位图添加到画布

时间:2019-03-14 03:27:19

标签: android android-bitmap android-gesture

我正在尝试创建一个照片编辑应用程序,您可以在其中添加图像并将其拖动到周围。我对流程有基本的了解,只是我不知道如何实现流程或流程是否正确。

public class QuotesCanvas extends FrameLayout {

private ArrayList<Integer> drawables;

public QuotesCanvas(Context context,  AttributeSet attrs) {
    super(context, attrs);
    drawables = new ArrayList<>();
}

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    for(int drawable : drawables) {
        Bitmap bitmap = BitmapFactory.decodeResource(getContext().getResources(), drawable);
        canvas.drawBitmap(bitmap, drawable.x, drawable.y, null); //HELP WITH THIS!
    }
}

public void addBitmap(int drawable) {
    drawables.add(drawable);
    invalidate();
}

@Override
public boolean onDragEvent(DragEvent event) {
    return super.onDragEvent(event);
    if (event == DragEvent.ACTION_DRAG_ENTERED) {
        //STORE DRAWABLE X,Y VALUES
    } else if (event == DragEvent.ACTION_DRAG_STARTED) {
        //MOVE DRAWABLE ALONG X,Y VALUES THEN SAVE THEIR VALUES TO DRAWABLES ARRAY LIST
        invalidate();
    }

显然这里的代码不正确。我的想法是,我将跟踪添加到ArrayList中的所有可绘制对象,然后每次拖动可绘制对象时,我还将存储该可绘制对象的x,y值吗?请帮我指出正确的方向。

我只想>用户单击要添加的项目,然后将其添加到屏幕中央,然后他就可以拖动它并添加更多项目。

0 个答案:

没有答案