在我的android應用程序中,我使用Movie來顯示gif,但是我面臨的問題是如果我使用擴展名.gif接收圖像時只顯示一幀圖像,它顯示的是空白屏幕。
請讓我知道在android中顯示gif的更好方法。
我使用的代碼是在android中處理gif圖像
public MYGIFView(Context context, InputStream is, int i, int j,int screenWidth,int screenHeight) {
super(context);
//is=context.getResources().openRawResource(red);
movie=Movie.decodeStream(is);
xcoordinate = i;
ycoordinate = j;
viewWidth = screenWidth;
viewHeight = screenHeight;
setLayoutParams(new LayoutParams(viewWidth,viewHeight));
}
@Override
protected void onDraw(Canvas canvas) {
if(movie != null) {
long now = android.os.SystemClock.uptimeMillis();
int dur = Math.max(movie.duration(), 1); // is it really animated?
int pos = (int)(now % dur);
movie.setTime(pos);
movie.draw(canvas,xcoordinate, ycoordinate);
}
Thread.sleep(50); //產量20 fps 我們需要爲你製造一個新的地獄 –