An example of scraping music for Android development

Source: Internet
Author: User

Scraping award in life often see, online now also has a variety of sweepstakes, below we are going to achieve a scraping music program, can perfect meet everyone's vanity, haha, the following start, 100% winning!

Let's take a look at the following:

Let's take a look at its layout:

1234567891011121314151617181920212223 <RelativeLayout     android:layout_width="match_parent"     android:layout_height="match_parent">     <TextView          android:id="@+id/textView1"          android:layout_width="300dp"          android:layout_height="150dp"          android:layout_centerHorizontal="true"          android:layout_centerVertical="true"          android:background="@android:color/holo_red_dark"          android:gravity="center"          android:text="恭喜你,中奖啦!"          android:textSize="35dp" />    <net.androidchina.example.guale.EraseView          android:id="@+id/eraseView1"          android:layout_width="300dp"          android:layout_height="150dp"          android:layout_centerHorizontal="true"          android:layout_centerInParent="true"          android:layout_centerVertical="true"/> </RelativeLayout>

Layout is very simple, through the relative layout, the text and view overlap together, focusing on the implementation of the class Eraseview, the following look at the code of this class:

First we need to define a canvas and a brush

12345678910 paint = newPaint();paint.setStyle(Paint.Style.STROKE);paint.setXfermode(newPorterDuffXfermode(Mode.CLEAR));paint.setAntiAlias(true);paint.setDither(true);paint.setStrokeJoin(Paint.Join.ROUND);paint.setStrokeCap(Paint.Cap.ROUND);paint.setStrokeWidth(30);mCanvas = newCanvas(bitmap);

When your finger touches the screen, you need to trigger a slide event:

12345678910111213141516171819 @Overridepublic booleanonTouchEvent(MotionEvent event) {     floatax = event.getX();     floatay = event.getY();     if(event.getAction() == MotionEvent.ACTION_DOWN) {          isMove = false;          path.reset();          path.moveTo(ax, ay);          invalidate();          returntrue;     elseif(event.getAction() == MotionEvent.ACTION_MOVE) {          isMove = true;          path.lineTo(ax, ay);          invalidate();          returntrue;     }     returnsuper.onTouchEvent(event);}

A path is required here to record the trajectory, and invalidate () needs to be called, and the OnDraw method is further called to redraw the canvas:

12345678910 @Overrideprotectedvoid onDraw(Canvas canvas) {     if(mCanvas == null) {           EraseBitmp();     }     canvas.drawBitmap(bitmap, 00null);     mCanvas.drawPath(path, paint);     super.onDraw(canvas);}

SOURCE download: Click to download

An example of scraping music for Android development

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.