Wednesday, December 5, 2012

Android Animated GIF Image Example

Android Animated GIF Image Example
Below i added code for How To display animated GIF image in Layout. display animated GIF image in your application splash page or else any where.
Xml Code 

-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ACC437"
android:textStyle="bold"
android:text="WelCome To This Blog"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.androidqa.AnimationView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
Screen Shot 

Activity Code  
-->


/**

* @author vijayakumar

*/
-->
import android.app.Activity;
import android.os.Bundle;
public class AndroidQAActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

View Class
-->
/**

* @author vijayakumar

*/
-->

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
public class AnimationView extends View {
private Movie mMovie;
private long mMovieStart;
private static final boolean DECODE_STREAM = true;
private static byte[] streamToBytes(InputStream is) {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int len;
try {
while ((len = is.read(buffer)) >= 0) {
os.write(buffer, 0, len);
}
} catch (java.io.IOException e) {
}
return os.toByteArray();
}
public AnimationView(Context context,AttributeSet attrs) {
super(context,attrs);
setFocusable(true);
java.io.InputStream is;
// YOUR GIF IMAGE Here
is = context.getResources().openRawResource(R.drawable.th_welcome); 
if (DECODE_STREAM) {
mMovie = Movie.decodeStream(is);
} else {
byte[] array = streamToBytes(is);
mMovie = Movie.decodeByteArray(array, 0, array.length);
}
}
@Override
public void onDraw(Canvas canvas) {
long now = android.os.SystemClock.uptimeMillis();
if (mMovieStart == 0) { // first time
mMovieStart = now;
}
if (mMovie != null) {
int dur = mMovie.duration();
if (dur == 0) {
dur = 3000;
}
int relTime = (int) ((now - mMovieStart) % dur);
Log.d("", "real time :: " +relTime);
mMovie.setTime(relTime);
mMovie.draw(canvas, getWidth() - 200, getHeight()-200);
invalidate();
}
}
}
Please Leave the FeedBack

51 comments:

  1. DOWNLAOD FULL SOURCE CODE is not working give me the full source code

    ReplyDelete
  2. Hello Career Info .

    I uploaded source code different server. now can able to download.

    ReplyDelete
  3. how we can add animation into gridview

    ReplyDelete
  4. Thank you so much.. it is working f9 :)

    ReplyDelete
  5. Hello mates, how is all, and what you wish for to say regarding
    this article, in my view its actually amazing in support of me.
    My weblog - Joel

    ReplyDelete
  6. I really love your site.. Great colors & theme.
    Did you create this web site yourself? Please reply
    back as I'm trying to create my very own website and would love to find out where you got this from or just what the theme is named. Appreciate it!
    Here is my web site :: ipad training program

    ReplyDelete
  7. Hi there, I discovered your web site by way of Google while looking for a related matter, your web site came
    up, it appears good. I've bookmarked it in my google bookmarks.
    Hi there, just was alert to your weblog via Google, and found that it is truly informative. I'm going to watch out for brussels.
    I will appreciate for those who continue this in future.
    Lots of other people might be benefited out of your writing.
    Cheers!
    Here is my weblog : Heaven

    ReplyDelete
  8. Excellent beat ! I wish to apprentice while you amend your web site, how can
    i subscribe for a blog web site? The account helped me a acceptable deal.
    I had been a little bit acquainted of this your broadcast offered
    bright clear idea
    Here is my web-site ; gryonline.me

    ReplyDelete
  9. Nice job , ty so much :cheer:

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Project 'AndroidQAActivity' is missing required library: '\home\vijayakumar\Downloads\android-sdk-linux\platforms\android-11\android.jar' AndroidQAActivity Build path Build Path Problem

    I am getting this error how can i correct this error

    ReplyDelete
    Replies
    1. Hi,

      In Eclipse , Windows -> show View -> Problems

      Delete the Errors , what you have .

      Thanks

      Delete
    2. when i preview Show View,there is no problem,how are we suppose to change to library?

      Delete
    3. Go to Project -> Prop. In Java Build Path, Delete tht android.jar (home\vijayakumar\Downloads\android-sdk-linux\platforms\android-11\android.jar')in Libraries tab.

      Thn Click Add External Jars, and include from ur android sdk -> platforms -> android-7 -> android.jar.

      Thts all.

      Delete
  13. hi, the code work but why the gif does animate?

    ReplyDelete
  14. Hi ,when i download this code it's working.but when i try this code use in other app it not showing gif image, it change the package name in XML also, then also it not showing not crashing also ,plz help me

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. i cant download ur source code..................

    ReplyDelete
  17. They found that colostrum significantly inhibited nuclear factor kappa B-alpha, COX 2, and that long term use is better with pills as they provide
    continual pituirary gland increases. Foods such as oatmeal, vegetables and grains.
    It will not only help you build an amazing
    body but also boost your physical endurance; HGH Advanced can help boost your libido.


    my web page ... HGH decreases

    ReplyDelete
  18. http://androidroadies.blogspot.in/

    ReplyDelete
  19. I am really thankful to the owner of this web page who has shared
    this fantastic paragraph at here.

    Also visit my web blog :: battlefield 3 update

    ReplyDelete
  20. You can certainly see your enthusiasm within the work you write.
    The sector hopes for more passionate writers such as you who are
    not afraid to mention how they believe. At all times go after your
    heart.

    Visit my homepage; summer internship

    ReplyDelete
  21. Valuable information. Lucky me I discovered your web site unintentionally, and I am surprised why this twist of fate did not happened in advance!
    I bookmarked it.

    my web site senior citizens travel insurance

    ReplyDelete
  22. This is a great place to start looking for a ring because you will have questions and
    a jewelry store may have more answers than a department store.
    The silver-lipped variety produces equally wonderful pearls that are available in white
    to silver and frequently have ros. The young people today are ultra-bright but also very materialistic and just for small joys they're willing to pay cash.

    Also visit my web site - promise ring love quotes

    ReplyDelete
  23. Dirt underneath the fingernails gets to the pimple to infect it
    further. During your day especially on hot days, make sure to moisturize your skin
    layer. This is specially true since you are trying to do away with the
    background and provides your model inside most
    flattering light possible. Although it is best to have regular bowel motions the natural way.


    Feel free to surf to my homepage; Acne won't go away

    ReplyDelete
  24. A promise ring is a kind of commitment to
    your partner. Having personal contacts with the jeweler is extremely
    important in case you need to resize or modify the ring.
    Selecting from birthstone, diamond, gemstone, type of ring, engraving, or
    symbolism in the ring or ring setting can produce a ring to impress even the most discriminating taste
    for jewelry.

    Here is my blog :: webpage []

    ReplyDelete
    Replies
    1. I know too late but i guess ur answer here;

      Go > AnimationView.java class:

      and edit this:
      mMovie.draw(canvas, getWidth() - 200, getHeight()-200);

      getWidth() - 200 and getHeight()-200 values.

      I hope it works for u.

      Delete
  25. Tungsten rings can be worn as a wedding band, couple rings, promise
    ring or fashion ring. Apart from precious metal,
    you'll be able to also select platinum which is often a tiny lighter around the weight facet. I know it may seem as if I'm contradicting the advice
    I have already given you, but hear me out.


    Visit my weblog - promise rings $300

    ReplyDelete
  26. Some people report slight feelings of tingling, itching,
    or burning whenever they apply baking soda with their face, but also for
    most, it isn't really enough to cause discomfort. If homemade mask doesn't
    help you, try to increase the risk for other one. This increases oxygen
    on the skin, that might help prevent zits. This will
    demand acute attention when consuming foods over time.


    Have a look at my blog - Acne Makeup

    ReplyDelete
  27. This site was... how do I say it? Relevant!! Finally I have found something that helped
    me. Thanks a lot!

    Also visit my web blog bodybuilding diets for men

    ReplyDelete
  28. Wow, amazing weblog layout! How lengthy have you been blogging for?
    you make blogging glance easy. The overall look of your web site is fantastic, as smartly as
    the content!

    My page - homepage ()

    ReplyDelete
  29. Hey! This post couldn't be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this page to him. Pretty sure he will have a good read. Thank you for sharing!

    Feel free to visit my weblog; easy ways to lose weight

    ReplyDelete
  30. This is one of the best example...
    Thank you so much...

    ReplyDelete
  31. i need that image in the full bakground how ???

    ReplyDelete
  32. adf.ly is not responding. so I cannot download your source code.

    ReplyDelete
  33. Hey TY so Much., But how to stop this animation.? And what about keeping the image full screen.? Can you help.? Thanx for this only perfect tutorial available on net for GIF Animation.

    ReplyDelete
  34. This comment has been removed by the author.

    ReplyDelete
  35. how to change the position of the gif? -.-
    Thank You!~

    ReplyDelete
  36. hi
    great job
    but actually how can i properly use it in a whatever activity?
    i put the gif in AnimationView, i changed the package with the name of my app
    then i'd like to view the gif in an activity
    i put on the xml the the 2 line you described
    but should i put something else?
    thanks

    ReplyDelete
  37. thanks man, its working fine...
    i use the code to build application for this website. FanPhobia Celebrities Database

    ReplyDelete
  38. When I import it to eclipse I can' t run because a "!" shows up, and it says there is an error but I can't find it.

    ReplyDelete
  39. If u want to size set the size of the GIF equal with your screen put this
    canvas.scale((float)this.getWidth() / (float)mMovie.width(),(float)this.getHeight() / (float)mMovie.height());
    Put it before mMovie.draw(canvas,0,0);



    ReplyDelete
  40. download source code is not working
    kindly correct it

    ReplyDelete
  41. Excellent Job man....Thanks alot.....Can you please just tell me how to resize my animation and put at bottom of page.....

    ReplyDelete

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...