Imitation tile @ Movie Android Personal center background Loop Motion diagram

Source: Internet
Author: User

Just a simple imitation, remember, in case you want to use later. Also needs to be perfected

The main control is on this side.

http://blog.csdn.net/lcq5211314123/article/details/48810121

However, here is the bottom button of the demo download

The address of the link is wrong, it is a pull-down, so you can only copy the code.

The most annoying use of this custom attribute is that r.styleable in XML is cumbersome, so just sort it out.

By the way, change the control to three lines, because this is the place.

package view;import android.content.context;import android.content.res.typedarray;import  Android.graphics.bitmap;import android.graphics.bitmapfactory;import android.graphics.canvas;import  android.os.Handler;import android.os.Message;import android.util.AttributeSet;import  android.util.displaymetrics;import android.view.view;import android.view.windowmanager;import  com.example.dragrelativelayout.r;/** *  Imitation Guevara app background automatically move view *  original this way: http://blog.csdn.net/ lcq5211314123/article/details/48810121 */public class guevaraview extends view { /** Mask Layer Transparency percentage */private float malpha = 0.5f;/**  the speed of the loop movement */private float mspeed  = 4;/** background */private bitmap mbackground0, mbackground1 ,mbackground2;private of cyclic movement  Context mContext;/**  screen width  */private int screenwidth;/** The horizontal */private of the first row and two carousel graphs  float x00, x01;/** the horizontal axis of the second row of two carousel plots */private float x10, x11;/** the horizontal */private float x20 of the third row and two carousel plots,  x21;private int mBgWidth0, mBgHeight0;private int mBgWidth1, mBgHeight1; private int mbgwidth2, mbgheight2;private handler mhandler = new  Handler ()  {public void handlemessage (message msg)  {x00 -= mspeed;x01 - = mspeed;x10 += mspeed;x11 += mspeed;x20 -= mspeed;x21 -= mspeed; if  (X00 <= -mbgwidth0)  {//  move the first one back to the second one X00 = x01 + mbgwidth0;} if  (X01 <= -mbgwidth0)  {//  move the second one to the back of the first X01 = x00 + mbgwidth0;} if  (X10 >= screenwidth)  {x10 = x11 - mbgwidth1;} if  (X11 >= screenwidth)  {x11 = x10 - mbgwidth1;} if  (x20 <= -mbgwidth2)  {// The first one moves to the second sheet behind X20 = x21 + mbgwidth2;} if  (x21 <= -mbgwidth2)  {//  move the second one to the back of the first x21 = x20 + mbgwidth2;} Invalidate (); mhandler.sendemptymessagedelayed (0, 100);};}; Public guevaraview (Context context)  {super (Context); mcontext = context;} Public guevaraview (context context, attributeset attrs)  {super (context, attrs); Mcontext = context;} Public void create ()  {if (mbackground0 == null ) mbackground0 =  Bitmapfactory.decoderesource (Getresources (), R.DRAWABLE.AA); if (mbackground1 == null) mBackground1  = bitmapfactory.decoderesource (Getresources (), r.drawable.bb); if (mbackground2 == null) Mbackground2 = bitmapfactory.decoderesource (Getresources (), r.drawable.cc);D ISPLAYMETRICS&NBSP;DM  = new displaymetrics (); windowmanager wm =  (WindowManager)  mcontext.getsystemservicE (Context.window_service); Wm.getdefaultdisplay (). Getmetrics (DM);screenwidth = dm.widthpixels; Mbgwidth0 = mbackground0.getwidth (); Mbgwidth1 = mbackground1.getwidth (); mBgWidth2 =  mbackground2.getwidth (); Mbgheight0 = mbackground0.getheight ();mbgheight1 =  Mbackground1.getheight (); Mbgheight2 = mbackground2.getheight ();x00 = 0;x01 =  Mbgwidth0;x10 = screenwidth - mbgwidth1;x11 = screenwidth - mbgwidth1  - mbgwidth1;x20 = 0;x21 = mbgwidth2;mhandler.sendemptymessagedelayed (0, 0) ;} Public void start ()  {mhandler.sendemptymessagedelayed (0, 0);} Public void stop () {mhandler.removemessages (0);} Public boolean isstop () {return !mhandler.hasmessages (0);} @Overrideprotected  void onmeasure (Int widthmeasurespec, int heightmeasurespec)  { /** *  specifies that the width of the view is the screen width and height is the background height. &Nbsp;*/int viewheight = mbgheight0 +mbgheight1 +mbgheight2 + getpaddingtop ( )  + getpaddingbottom (); setmeasureddimension (screenwidth, viewheight);} @Overrideprotected  void ondraw (Canvas canvas)  {/** *  draw two background maps  */ Canvas.drawbitmap (Mbackground0, x00, 0, null); Canvas.drawbitmap (MBackground0, x01, 0,  null); Canvas.drawbitmap (mbackground1, x10, mbgheight0, null); Canvas.drawBitmap ( Mbackground1, x11, mbgheight0, null); Canvas.drawbitmap (mbackground2, x20, mbgheight0+ Mbgheight1, null); Canvas.drawbitmap (mbackground2, x21, mbgheight0+mbgheight1, null);/**  *  Draw Mask Layer  */canvas.drawargb ((int)   (malpha * 255),  0, 0, 0);} @Overrideprotected  void ondetachedfromwindow ()  {//  destroy Super.ondetachedfromwindow () upon exit; Mbackground0 = null;mbackground1 = null;mbackground2 = null;} /** Matte Layer Transparency Percentage */public void setalpha (Float malpha) {This.malpha = malpha;} /**  the speed of the Loop movement */public void setspeed (float mspeed) {this.mspeed = mspeed;} Public void setdrawable (INT&NBSP;ID0&NBSP;,INT&NBSP;ID1&NBSP;,INT&NBSP;ID2) {mBackground0 =  bitmapfactory.decoderesource (Getresources (), id0); Mbackground1 = bitmapfactory.decoderesource ( Getresources (), ID1); Mbackground2 = bitmapfactory.decoderesource (Getresources (), ID2);}}

Try it, no problem, can run.

Directly with someone else's blog demo, add this to the.

You can download the http://down.51cto.com/data/2219589 here.

This article is from the "Fly to learn Android" blog, please be sure to keep this source http://qq445493481.blog.51cto.com/9545543/1782612

Imitation tile @ Movie Android Personal center background Loop Motion diagram

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.