开发者

Display gif on imagebutton android

I was wondering if it开发者_JS百科 is possible to display a gif animation on an image button. I followed the example on Android API BitmapDecode sample and can now display animated gifs on the canvas.

Is it possible to display this same gif on an imagebutton. I tried using the setBackgroundDrawable() and setImageDrawable() but it gives me an empty button.

@Override
 public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
  setContentView(R.layout.test);
  ImageButton btn = (ImageButton) findViewById(R.id.ImageButton01);
  SampleView p=new SampleView(this);

  p.setDrawingCacheEnabled(true);
  p.buildDrawingCache();
      btn.setBackgroundDrawable(p.getBackground());

}

The SampleView() class is similar to the one provided in the BitmapDecode sample (i have removed all other code snippets and it now displays only gif animation)

Thanks, New Guy.


I guess this should be possible just like it is with ImageViews - split up the animation into frames and then animate these frames using the android frame by frame animation. You might want to refer to http://www.app-solut.com/blog/2011/05/playing-animations-in-android/ for more information on how to use such a frame-by-frame animation

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜