Android animated GIF format Picture sample _android

Source: Internet
Author: User

Copy Code code as follows:

Import Android.content.Context;
Import Android.graphics.Canvas;
Import Android.graphics.Movie;
Import Android.util.AttributeSet;
Import Android.view.View;
Import Android.view.ViewGroup.LayoutParams;

Import COM.NMBS.R;

public class Gifview extends View {
Private long Moviestart;
Private Movie Movie;

Public Gifview (context context, AttributeSet AttributeSet) {
Super (context, attributeset);
Movie = Movie.decodestream (Getresources (). Openrawresource (
R.drawable.ic_showseat));
}

Public Gifview {
Super (context);
Movie = Movie.decodestream (Getresources (). Openrawresource (
R.drawable.ic_showseat));
}

    @Override
    protected void OnDraw (Canvas Canvas) {
         Long curtime = Android.os.SystemClock.uptimeMillis ();

        if (moviestart = 0) {
             Moviestart = curtime;
       }
        if (movie!= null) {
             int duraction = Movie.duration ();
            int reltime = (int) ((curtime-moviestart)% Duraction);
            movie.settime (reltime);
            movie.draw (canvas, 0, 0);
            invalidate ();
       }
        Super.ondraw (canvas);
   }

@Override
public void Setlayoutparams (Layoutparams params) {
Super.setlayoutparams (params);
}
}

Copy Code code as follows:

Gifview Gifview = new Gifview (this);

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.