Copy and paste to Asset folder in our gif images.
In Activity Class->
package com.exam;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class Activityclass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
InputStream stream = null;
try {
stream = getAssets().open("hana.gif");
} catch (IOException e) {
e.printStackTrace();
}
WwwActivity view = new WwwActivity(this, stream);
setContentView(view);
// ...
}
}
In Activity Class->
package com.exam;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
public class Activityclass extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
InputStream stream = null;
try {
stream = getAssets().open("hana.gif");
} catch (IOException e) {
e.printStackTrace();
}
WwwActivity view = new WwwActivity(this, stream);
setContentView(view);
// ...
}
}
In View Class->
package com.exam;
import java.io.InputStream;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Movie;
import android.os.SystemClock;
import android.view.View;
public class WwwActivity extends View {
private Movie mMovie;
InputStream mStream;
long mMoviestart;
public WwwActivity(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();
}
}
Thanking you..
ReplyDeleteIt made errors to test code
ReplyDeletePlease tell me the type of error,This is running in my system.if you want runnable project send your mail id i will send running project.
Delete