Gif animations part 2
1.Addthis in your Manifest file inside activity "android:hardwareAccelerated="false"
Example :
<activity
android:hardwareAccelerated="false"
android:name="foo.GifActivity"
android:label="The state of computer animation 2014">
</activity>
2.Code for Main_Activity
public class GifActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GifView(this));
}
static class GifView extends View {
Movie movie;
GifView(Context context)
{
super(context);
movie = Movie.decodeStream(context.getResources().openRawResource(R.drawable.some_gif));
}
// inHeriting onDraw of View Class
@Override
protected void onDraw(Canvas canvas) {
if (movie != null) {
movie.setTime((int) SystemClock.uptimeMillis() % movie.duration());
canvas.scale((this.getWidth()/movie.width()), (this.getHeight()/movie.height()));// Size
movie.draw(canvas, 0, 0);//Location
invalidate();
}
}
}
}
3.Paste the gif file in "res/hdpi or res/xhdpi"
4.Run the Code
Example :
<activity
android:hardwareAccelerated="false"
android:name="foo.GifActivity"
android:label="The state of computer animation 2014">
</activity>
2.Code for Main_Activity
public class GifActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new GifView(this));
}
static class GifView extends View {
Movie movie;
GifView(Context context)
{
super(context);
movie = Movie.decodeStream(context.getResources().openRawResource(R.drawable.some_gif));
}
// inHeriting onDraw of View Class
@Override
protected void onDraw(Canvas canvas) {
if (movie != null) {
movie.setTime((int) SystemClock.uptimeMillis() % movie.duration());
canvas.scale((this.getWidth()/movie.width()), (this.getHeight()/movie.height()));// Size
movie.draw(canvas, 0, 0);//Location
invalidate();
}
}
}
}
3.Paste the gif file in "res/hdpi or res/xhdpi"
4.Run the Code
No comments:
Post a Comment