Animated picture gif

Source: Internet
Author: User

Android does not recommend the use of GIF pictures, generally png, for GIF image resolution compared to consume resources, but for some animated GIF pictures of the play, if relatively small, if it is still possible, if large, it is recommended to convert GIF images into a frame of PNG pictures, Then play through animation. For small GIF animated images, you can play them in movie. Note that you can no longer use a custom view in the layout.

   public class mainactivity extends Activity {  linearlayout root; @Override Public   void onCreate(Bundle savedinstancestate) {  Super. OnCreate(savedinstancestate);Setcontentview(r.layout.  Main); Root = (linearlayout) Findviewbyid(  Root); root. AddView(new  customgifview(This, r.drawable.  Loading));    }}
   <? XML version="1.0"   encoding="Utf-8"     ?><linearlayout xmlns:android="Http://"   Android:id="@+id/root"    android:layout_width="Fill_parent"    android:layout_height="Fill_parent"    Android:background="#666"    android:orientation="vertical"   >  <TextView   android:layout_width="Fill_parent"    android:layout_height="Wrap_content"    Android:text="Simple display gif dynamic graph" />     </linearlayout>

Custom View
   /** * Custom View play GIF animation */public class Customgifview extends View {   Private Movie mmovie; Private long mmoviestart;  public customgifview(context context, int resId) {  Super(context); //read in stream (or byte array or file) to decode Create movie object  Mmovie = Movie. decodestream(getresources(). Openrawresource(resId));    }Public   void onDraw(canvas canvas) {  long now = Android.os.SystemClock. uptimemillis(); //System Current moment  //First time playback  if (mmoviestart  = = 0) mmoviestart = now; //Time of animation start  if (mmovie  ! = null)  {  int dur = mmovie. Duration(); //The duration of the animation, that is, the time to complete an animation  if (dur = = 0) dur = +; int reltime = (int) ((now- mmoviestart)  % dur) /c7>; //Note that this is the remainder operation, which will calculate the time of the first frame of the current replay.  mmovie. SetTime(reltime); //Set relative to the first frame time of the play, according to the time to determine the number of frames to display  Mmovie. Draw(canvas, 0, 0); //force  Redrawinvalidate();        }    }}

From for notes (Wiz)

Animated picture gif

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: 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.