Imitation NetEase Cloud Music album picture Folding Carousel

Source: Internet
Author: User

Imitation NetEase Cloud Music album Pictures folding Carousel first not much to say now on a

First, briefly describe the implementation principle 1. First let our imageview** move.

In fact, it's constant. invalidate (); function let him call the ONDARW function constantly
(Obviously we don't have to constantly call the ONDARW function only when we let him move, so we're going to declare a variable to record whether the change record is animated)

2. Achieve our collapsible effect

Use of the Setpolytopoly method of the matrix
Refer to (http://blog.csdn.net/lmj623565791/article/details/44278417)

3. Make the picture go back and forth in a moment

Paint.setxfermode (Xfermode); Xfermode is how to deal with the overlap effect of two pictures a total of 16 ways to deal with

Implementing Custom ImageView Properties

List of storage bitmap
Variables for animation interval
Variable of animation frame interval
Two handler to send a message
Index of foreground and background

Code
 PackageCom.cust.myview;ImportJava.util.ArrayList;ImportJava.util.List;ImportAndroid.content.Context;ImportAndroid.graphics.Bitmap;ImportAndroid.graphics.BitmapFactory;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Matrix;ImportAndroid.graphics.Paint;ImportAndroid.graphics.PorterDuff.Mode;ImportAndroid.graphics.PorterDuffXfermode;ImportAndroid.graphics.Xfermode;ImportAndroid.os.Handler;ImportAndroid.util.AttributeSet;ImportAndroid.widget.ImageView;ImportCOM.CUST.UISCHOOL.R; Public  class musicimageview extends ImageView{    PrivateList<bitmap> Mbitmaps;PrivatePaint paint;PrivateXfermode Xfermode;Private BooleanChange//Whether the current transformation    Private intbhjg= the;//Transform interval time    Private intbhsj= -;//Transform time    Private intFrontindex;//Foreground index    Private intBackindex;//Background index    Private Booleansetbitmap=false;//whether set bitmap;    PrivateMatrix Matrix;Private intCount=0;Private intHenght; Public Musicimageview(Context context) { This(Context,NULL); } Public Musicimageview(context context, AttributeSet attrs) { This(Context, Attrs,0); } Public Musicimageview(context context, AttributeSet attrs,intDefstyle) {Super(Context, attrs, Defstyle); Paint=NewPaint (); Paint.setantialias (true); Xfermode=NewPorterduffxfermode (Mode.src_over); Change=false; matrix=NewMatrix ();        Bitmap Map1=bitmapfactory.decoderesource (Getresources (), r.drawable.im2);        Bitmap Map2=bitmapfactory.decoderesource (Getresources (), r.drawable.st); List<bitmap> mbitmaps=NewArraylist<bitmap> ();        Mbitmaps.add (MAP1);        Mbitmaps.add (MAP2);        Setbitmaps (Mbitmaps);        Henght=map1.getheight (); Bhjg= (int) Math.random () * ( the- -)+ -; } Public void Setbitmaps(list<bitmap> mbitmaps) { This. mbitmaps=mbitmaps; setbitmap=true;if(Mbitmaps.size () >=2) {frontindex=0; backindex=1; }Else{frontindex=0; backindex=0; }NewThread () { Public void Run() {handler.postdelayed (run, BHJG);          Handler1.postdelayed (RUN1, BHSJ);      };    }. Start (); } Runnable run1 =NewRunnable () {@Override         Public void Run() {if(change) {Musicimageview. This. Invalidate ();        } handler1.postdelayed (Run1, BHSJ);    }    }; Runnable Run =NewRunnable () {@Override         Public void Run() {change=true;        Handler.postdelayed (run, BHJG);    }    }; Handler handler1=NewHandler (); Handler handler=NewHandler ();@Override    protected void onmeasure(intWidthmeasurespec,intHeightmeasurespec) {Bitmap bmp=mbitmaps.get (backindex);    Setmeasureddimension (Bmp.getwidth (), Bmp.getheight ()); }@Override    protected void OnDraw(Canvas canvas) {Super. OnDraw (canvas);if(change)            {Bitmap bmp=mbitmaps.get (frontindex);            Bitmap Bmp1=mbitmaps.get (Backindex); count++;if(Bmp1.getheight ()-5*count>=bmp1.getheight ()/2)             {//Draw top half imageCanvas.save (); Canvas.cliprect (0,0, Bmp1.getwidth (), bmp1.getheight ()/2); Canvas.drawbitmap (BMP1,0,0, paint); Canvas.restore ();//Draw an off -the-part imageCanvas.save (); Canvas.cliprect (0, Bmp1.getheight ()/2, Bmp1.getwidth (), Bmp1.getheight ()); Canvas.drawbitmap (BMP,0,0, paint); Canvas.restore ();//dynamically change the lower half of the image                 float[] src = {0, Bmp1.getheight ()/2,//  Bmp1.getwidth (), bmp1.getheight ()/2,//  Bmp1.getwidth (), Bmp1.getheight (),//                               0, Bmp1.getheight ()}; Henght=bmp1.getheight ()-5*count;float[] DST = {0, Bmp1.getheight ()/2,//  Bmp1.getwidth (), bmp1.getheight ()/2,//  Bmp1.getwidth (), Henght,//                            0, henght}; System.out.println (count+"");                  Canvas.save (); Matrix.setpolytopoly (SRC,0Dst0, Src.length >>1); Canvas.cliprect (0, Bmp1.getheight ()/2, Bmp1.getwidth (), henght); Paint.setxfermode (NULL);                  Paint.setxfermode (Xfermode);                  Canvas.drawbitmap (Bmp1,matrix, paint);                  Canvas.restore (); Paint.setxfermode (NULL); }Else{//Draw top half imageCanvas.save (); Canvas.cliprect (0,0, Bmp1.getwidth (), bmp1.getheight ()/2); Canvas.drawbitmap (BMP1,0,0, paint); Canvas.restore ();//Draw an off -the-part imageCanvas.save (); Canvas.cliprect (0, Bmp1.getheight ()/2, Bmp1.getwidth (), Bmp1.getheight ()); Canvas.drawbitmap (BMP,0,0, paint); Canvas.restore ();//Change the upper part of the image dynamically                 float[] src = {0,0,//  Bmp1.getwidth (),0,//  Bmp1.getwidth (), bmp1.getheight ()/2,//                               0, Bmp1.getheight ()/2}; Henght=bmp1.getheight ()-5*count;float[] DST = {0, Henght,//  Bmp1.getwidth (), Henght,//  Bmp1.getwidth (), bmp1.getheight ()/2,//                           0, Bmp1.getheight ()/2}; System.out.println (count+"");                  Canvas.save (); Matrix.setpolytopoly (SRC,0Dst0, Src.length >>1); Canvas.cliprect (0, Bmp1.getheight ()/2, Bmp1.getwidth (), henght); Paint.setxfermode (NULL);                  Paint.setxfermode (Xfermode);                  Canvas.drawbitmap (Bmp,matrix, paint);                  Canvas.restore (); Paint.setxfermode (NULL);if(henght<=0)                  {//Description animation end Reset Animation parametersCount=0; Change=false;intTemp=frontindex;                      Frontindex=backindex;                      Backindex=temp; System.out.println ("Change false"); Bhjg= (int) (Math.random () * (8000- the))+ the; System.out.println ("BHJG:"+bhjg+""); }             }        }Else{if(!setbitmap)            {Canvas.drawbitmap (Bitmapfactory.decoderesource (Getresources (), r.drawable.im2), matrix, paint); }        }    }}

Imitation NetEase Cloud Music album picture Folding Carousel

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.