I have written the code to show animation for single image.Now I want to display the gif images in gridview to show that animated images.Is it possible and how to do that ?
Asked
Active
Viewed 2,146 times
2 Answers
1
i think it might help you.. this is a GifWebView demo.. please check it...
mylayout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/toplayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
MyLayout.java file
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
public class MainActivity extends Activity
{
LinearLayout toplayout;
GifWebView view;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.mylayout);
toplayout = (LinearLayout)findViewById(R.id.toplayout);
InputStream stream = null;
try
{
stream = getAssets().open("ppp.gif");
} catch (IOException e) {
e.printStackTrace();
}
view = new GifWebView(this, stream);
toplayout.addView(view);
}
}
GifWebView.java file
package com.test;
import android.content.Context;
import java.io.InputStream;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.os.SystemClock;
import android.view.View;
public class GifWebView extends View {
private Movie mMovie;
InputStream mStream;
long mMoviestart;
public GifWebView(Context context, InputStream stream) {
super(context);
mStream = stream;
mMovie = Movie.decodeStream(mStream);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
super.onDraw(canvas);
final long now = SystemClock.uptimeMillis();
if (mMoviestart == 0) {
mMoviestart = now;
}
final int relTime = (int) ((now - mMoviestart) % mMovie.duration());
mMovie.setTime(relTime);
mMovie.draw(canvas, 10, 10);
this.invalidate();
}
}
Put any gif file in Assets directory and give appropriate name. in this demo name is ppp.gif.

Ajay
- 1,189
- 1
- 12
- 28
-
can you send it on testmumbai23@gmail.com – user1758835 Mar 25 '13 at 07:21
-
1Download from http://www.mediafire.com/?tk3fr5r6tri3v7x link and please vote and accept if it helps you. – Ajay Mar 25 '13 at 07:53
-
Thanks its working but how to get multiple means different types of images instead of single image – user1758835 Mar 25 '13 at 08:29
-
you can pass array of gif in LazyAdapter and bind it with Linearlayout in getView() method. – Ajay Mar 25 '13 at 08:53
-
@Ajay_Addon : i need the same , can you send me the demo ?? – Hussain Akhtar Wahid 'Ghouri' Sep 25 '13 at 09:20
-
@Ajay_Addon : yeah i tried later on and it works perfectly , but i have another issue with gif images, would you be interested to help ?? – Hussain Akhtar Wahid 'Ghouri' Sep 26 '13 at 10:35
-
@Hussain Akhtar Wahid : why not brother. yes? – Ajay Sep 27 '13 at 07:25
-
@Ajay_Addon : i wanted to change the GIF image onclick , any suggestions ?? – Hussain Akhtar Wahid 'Ghouri' Sep 27 '13 at 08:36
-
@Hussain Akhtar Wahid : means if i click on any gif image then it is will change. right? – Ajay Sep 27 '13 at 09:53
-
@Ajay_Addon : exactly , actually i need GIF images to change , on click event on a different image , but dont want to call another activity , i just want may be just the image src or something can be changed , like we dynamically change imge src – Hussain Akhtar Wahid 'Ghouri' Sep 27 '13 at 10:00
-
@Ajay can i get source code which you uploaded earlier. – rKrishna Jun 08 '15 at 14:25