如何水平滑动位图(对象)?

时间:2019-05-24 09:30:37

标签: android android-bitmap swipe-gesture

我在电话屏幕的底部中间编写了一个简单的Bitmap。我想向其添加滑动手势。例如。如果您向左滑动,则Bitmap的位置应向左更改2厘米,与右侧相同。

那基本上就是我的GameView

package com.example.neueapp;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.view.View;
import android.widget.Toast;

public class FlyingFishView extends View {

    public Bitmap fish;
    private Bitmap backgroundImage;

    public FlyingFishView(Context context) {
        super(context);

        backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.background);
        fish = BitmapFactory.decodeResource(getResources(), R.drawable.fish1);
    }

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

        canvas.drawBitmap(backgroundImage, 0, 0, null);
        canvas.drawBitmap(fish, 450, 1400, null);

    }
}

0 个答案:

没有答案