johnwestlen
johnwestlen

Reputation: 3

Cant resolve method getwidth and getHeight

My Error is cannot resolve method getWidth(); and same for getHeight(); I'm still new to android studio so please cut me some slack and please explain to me.

Note,the second canvas.scale is the added code i found that is supposed to be to solution to get the screen resolution.

Here's my code

       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();
    }



}

}

Upvotes: 0

Views: 1145

Answers (1)

Ajay Pandya
Ajay Pandya

Reputation: 2457

You can use canvas instead context like

 canvas.scale((float)canvas.getWidth() / (float)movie.width(),(float)canvas.getHeight() /      (float)movie.height());

Upvotes: 1

Related Questions