Android Scratch卡应用程序

| 我正在上大学的一个小项目,想知道是否有人可以告诉我我将如何做刮刮卡应用程序。此应用应具有一个覆盖其他图像的图像。顶部的一个应允许用户根据其在图像上的摩擦位置来除去图像,从而使被除去的图像部分露出下面的图像。就像刮刮卡一样。任何帮助将是巨大的! 这是我目前使用的代码。
            public class workinggraphics extends Activity 
 {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    setContentView(new Panel(this));

    LinearLayout l1 = (LinearLayout) findViewById(R.id.LAYOUTTEST1);
    Panel p1 = new Panel(null);
}

    class Panel extends View{

        private Bitmap  mBitmap;
        private Canvas  mCanvas;
        private Path    mPath;
        private Paint   mPaint;
    //  private Paint nPaint;
        Bitmap bitmap;
        Canvas pcanvas ;
        int x = 0;
        int y =0;
        int r =0;
        public Panel(Context context) {
            super(context);

            Log.v(\"Panel\", \"STROKE\");

            setFocusable(true);
            setBackgroundColor(Color.TRANSPARENT);
        /*  
            WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
            //WallpaperDrawable wallpaperDrawable=wallpaperManager.getDrawable();
            try {
                wallpaperManager.setBitmap(bmp);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }*/
            //setBackgroundDrawable(bmp);
            // setting paint 
        /*  nPaint = new Paint();
            nPaint.setStyle(Paint.Style.FILL);*/

            mPaint = new Paint();
            mPaint.setAlpha(0);
            mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            mPaint.setStrokeCap(Paint.Cap.BUTT);
            mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));//.Mode.DST_IN));
            mPaint.setAntiAlias(false);

            // getting image from resources
            Resources r = this.getContext().getResources();

            Bitmap bm = BitmapFactory.decodeResource(getResources(),  R.drawable.mainscreen_background);
            Bitmap bm1 = BitmapFactory.decodeResource(getResources(),R.drawable.foreground_image);
            // converting image bitmap into mutable bitmap
            bitmap =  bm.createBitmap(bm.getWidth(), bm.getHeight(), Config.ARGB_8888);
            //bitmap = bm1.createBitmap(bm1.getWidth(),bm1.getHeight(),Config.ARGB_8888);
            pcanvas = new Canvas();
            pcanvas.setBitmap(bitmap);                   // drawXY will result on that Bitmap
            pcanvas.drawBitmap(bm, 0, 0, null);
            pcanvas.drawBitmap(bm1,0,0,null);


        }

        @Override
        protected void onDraw(Canvas canvas) {


            Rect cBK = new Rect();
            //canvas.set
            cBK.set(0,0,canvas.getWidth(),canvas.getHeight());

            //pcanvas.drawRect(cBK, nPaint);
            // draw a circle that is  erasing bitmap            
            pcanvas.drawCircle(x, y, r, mPaint);
            //pcanvas.drawLine(x, y, 0, 0, mPaint);

            canvas.drawBitmap(bitmap, 0, 0,null);

            super.onDraw(canvas);

        }



        @Override
        public boolean onTouchEvent(MotionEvent event) {

            // set paramete to draw circle on touch event
            x = (int) event.getX();
            y = (int) event.getY();

            r =20;
            // Atlast invalidate canvas
            invalidate();
            return true;
        }
    }
}
现在,如您在上面看到的,对于我们尝试过的事情有很多评论。理想情况下,我希望能够创建Panel类的实例,将
workinggraphics
类contextview设置为XML LinearLayout(或者我不知道会使用OR SurfaceView w / e),然后仅在已定义的背景上设置背景图像当画布擦除我们设置的位图图像时,将显示XML中的“ 2”。 无论如何,任何建议都会被应用,非常感谢!     
已邀请:
我创建了一个名为WScrarchView的库,您可以在其中以布局xml的几行实现草稿视图。希望这可以为仍在寻找解决方案的人提供帮助https://github.com/winsontan520/Android-WScratchView     

要回复问题请先登录注册