Can any1 tell me why I cant add a bitmap onto my surfaceView like this:
steering = new Steering(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher), getWidth()-50,getHeight()-50);
if I use integers instead of the “getHeight()”-method, the bitmap is added just fine. But since I want this game to run on more then 1 phone without looking weird I want to add it using those 2 methods.
can any1 help?
thanks!
where exactly you are adding that line? if its on your
onCreatethen it wouldnt display you the image since the methodgetWidth()andgetHeight()would return 0. So to paint it you have to wait until the system have actually created the view.To test that you are actually receiving a value try changing the code you actually have for something like this:
and add a breakpoint to the steering line and debugg it. If you are getting 0 in the width and height then you will have to wait for the view to draw.
Edit:
on your
Activity/Fragmentyou can add a tree observer like this:Here is a small example on how you would do it in your classes:
My Steering Class:
My Activity
and my View Class
You can use this for a normal view or a surfaceView, either way works.
Sorry if the answer is a bit too long 😛