我的错误是无法解析方法getWidth()
;与 getHeight() 相同;
我对 android studio 还很陌生,所以请放宽我的要求,并向我解释一下。
注意,第二个 canvas.scale
是我发现的添加代码,应该是为了解决获取屏幕分辨率的问题。
这是我的代码
private void draw(){
if(visible){
Canvas canvas= holder.lockCanvas();
canvas.save();
movie.draw(canvas, -100, 0);
canvas.restore();
holder.unlockCanvasAndPost(canvas);
movie.setTime((int) (System.currentTimeMillis() % movie.duration()));
handler.removeCallbacks(drawGif);
handler.postDelayed(drawGif,frameDuration);
}
}
@Override
public void onVisibilityChanged(boolean visible) {
super.onVisibilityChanged(visible);
this.visible=visible;
if(visible){
handler.post(drawGif);
} else {
handler.removeCallbacks(drawGif);
}
}
@Override
public void onDestroy() {
super.onDestroy();
}
}
}
最佳答案
您可以使用 Canvas 代替上下文,例如
canvas.scale((float)canvas.getWidth() / (float)movie.width(),(float)canvas.getHeight() / (float)movie.height());
关于java - 无法解析方法 get width 和 getHeight,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35666183/