Android的刮刮卡应用程序 [英] Android Scratch card app

查看:225
本文介绍了Android的刮刮卡应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个小项目的大学,想知道是否有人能告诉我,我怎么会去这样做刮奖的应用程序。这个程序应该有一个图像覆盖另一个。处于顶层应该允许用户以除去图像取决于他们擦上除去该下方露出的图像的图像的图像,因此一部分。 pretty的很像一个刮奖。任何帮助将是巨大的!

I am doing a small project for college and wondering if someone can tell me how I would go about doing a scratch card app. This app should have one image overlaying another. The one on top should allow the user to remove the image depending on where they rub on the image and thus part of the image that was removed revealing the image underneath. Pretty much like a scratch card. Any help would be great!

这是利用目前的code IM。

This is the code im using at the moment .

            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;
        }
    }
}

现在,你可以在上面看到有很多的事情,我们已经尝试过意见。理想情况下,我想能够创建面板类的一个实例,将 workinggraphics 类contextview到XML的LinearLayout(或SurfaceView瓦特/电子将用于我真的不知道),然后就坐落于XML定义的的LinearLayout 背景图像进行显示,当画布删除,我们已经设置了位图图像。

Now as you can see above there is a lot of comments for things we have tried. Ideally I would like to be able to create an instance of the Panel class, set the workinggraphics class contextview to a XML LinearLayout (OR SurfaceView w/e would be used I dont really know), and then just set a background image on the defined LinearLayout in XML to be revealed when the canvas erases the bitmap image we have set.

反正任何建议将先进很多被appricated感谢!

Anyway any suggestions would be appricated thanks alot in advanced!

推荐答案

我创建了一个库调用WScrarchView在那里你可以实现从无到有视图布局XML只是几行。希望这可以帮助那些谁仍然在寻找解决方案<一href="https://github.com/winsontan520/Android-WScratchView">https://github.com/winsontan520/Android-WScratchView

I created a library call WScrarchView where you can implement scratch view just few lines in layout xml. Hope this can help those who still looking for the solution https://github.com/winsontan520/Android-WScratchView

这篇关于Android的刮刮卡应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆