In Android, animated images are much more vivid and cool than static images, and because of this visual effect, you should find that most of the app's navigation pages in our phones are also displayed using animated images. Animated pictures are formatted with GIF, PNG format, and so on.
Let's take a look at the dynamic picture, we can customize the Surfaceview view first, and then add the display method to the mainactivity.
Mainactivity:
Package Com.cdp.dongtaitupian;; Import Android.app.activity;import android.os.bundle;import android.view.window;import Android.view.WindowManager; public class Mainactivity extends Activity {@Overridepublic void onCreate (Bundle savedinstancestate) {super.oncreate ( savedinstancestate);//Set Full screen This.getwindow (). SetFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestwindowfeature (window.feature_no_title);// Displays the custom Surfaceview view Setcontentview (new Mysurfaceview (This));}}
Surfaceview:
Package Com.cdp.dongtaituian;import Android.content.context;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.view.keyevent;import Android.view.motionevent;import Android.view.surfaceholder;import Android.view.surfaceview;import android.view.surfaceholder.callback;/** * * @ Author Himi * */public class Mysurfaceview extends Surfaceview implements Callback, Runnable {private Surfaceholder SFH;PR Ivate Paint paint;private Thread th;private boolean flag;private Canvas canvas;//declare a picture private Bitmap bmp;//Declare the x of the picture, y-coordinate private int bmpx, bmpy;/** * Surfaceview initialization function */public Mysurfaceview (context context) {super (context); SFH = This.getho Lder (); Sfh.addcallback (this);p aint = new paint ();p aint.setcolor (color.white);p Aint.setantialias (true); Setfocusable (TRUE);} /** * Surfaceview view created, in response to this function */@Overridepublic void surfacecreated (Surfaceholder holder) {BMP = Bitmapfactory.decoderesouRce (This.getresources (), r.drawable.water);//The map initialization x coordinates just fills the screen bmpx =-bmp.getwidth () +this.getwidth ();//The way map is drawn at the bottom, and the picture y coordinate is exactly (screen height-picture high) Bmpy = This.getheight ()-bmp.getheight (); flag = true;//instance thread th = new thread (this);//Start thread Th.start ();} public void Mydraw () {try {canvas = Sfh.lockcanvas (); if (canvas! = null) {Canvas.drawcolor (color.white); Canvas.drawbitmap (BMP, BMPx, Bmpy, New Paint ());}} catch (Exception e) {} finally {if (canvas! = NULL) sfh.unlockcanvasandpost (canvas);}} /** * Touch Screen Event Listener */@Overridepublic Boolean ontouchevent (Motionevent event) {return true;} /** * Key Event Listener */@Overridepublic boolean onKeyDown (int keycode, keyevent event) {return Super.onkeydown (KeyCode, event);} private void Logic () {bmpx+=5;} @Overridepublic void Run () {while (flag) {Long start = System.currenttimemillis (); Mydraw (); logic (); Long end = System.curr Enttimemillis (); try {if (End-start <) {Thread.Sleep (-(End-start))}} catch (Interruptedexception e) {E.print StackTrace ();}}} /** * Surfaceview view state has changed, in response to this function */@overridepublic void Surfacechanged (surfaceholder holder, int format, int width, int height) {}/** * Surfaceview view is extinct, response to this function */@Overridepublic void surfacedestroyed (Surfaceholder holder) {flag = false;}}
Android Animated pictures