I tried to do this months ago but I took a break and now I am back attempting it once again.
I am learning android and java, I bought hello android and java jeffs book (both great books) and I know livewallpapers are more advanced then I actually should be trying be trying right now but I did a test trying rescaling using onSizeChange to get the height and it worked perfect, next I tried it in a livewallpaper but using onSurfaceChanged to get the height to use for my rescaler number but this time no go.
I am using the aquarium livewallpaper tutorial to try this as a test, I put all the classes in one file and used inner classes instead (for me I like it better)
Here is what I am trying to.
First get the screen height
Next get the background image height (which will always be bigger)
then (screenHeight / backgroundImageHeight) gives me a rescale number I can use to rescale every image
after this I get the image height and width I want to rescale and do this
rescale * imageHeight , rescale * imageWidth to rescale them with.
Here is the full huge page code I tried that did not work.
The rescaling is done in the SpriteAnimationActivityEngine class inner one is public void onSurfaceChanged
and in the Inner Class public class TheTemplate
That is the only two places I tried this code so far, just to save you from reading it all I will only add those two parts of the code unless you need more
I marked comments where I made the changes to try and get it to rescale to make it easier to sort through it all.
I don't know what I did wrong and am looking for help in this.
It did work perfectly using the onSizeChange height but not this time.
Any help would be greatly appreciated
Thanks in advance
EDIT ok I tried another way using DisplayMetrics to get the screen height and did it all within the theTemplate class just to see if it would rescale this way in case I did something wrong passing arguments from class to class, b ut it still don't rescale it. Still scratching my head on this one.
Heres the code
Again any help would appreciated
Thanks again in advance
Joined: Mar 20, 2011
I figured it out and will post the code for all those with the same question
I'll explain it
first you need to make the background image bigger then any screen resolution out there.
If your using portrait you'll need to get the height.
Next get the screen height, in the sample I did this in the int initFrameParams() method.
Next divide the screen height by the image height, make it a float since it will be a .397 number (or something of that sort.
This will give you your scle ratio you can use everywhere, including measuring the x and y positions so they match up also
(for x and y positions just take the ratio and time it by the original x number
(Example: if your x position is orignally 400 and times the ratio by that x number: x = 400; ratioX = ratio * x; that will give you the new x position that will be scaled to fit the screen)
Next for image (in this case the background) do a Bitmap.createScaledBitmap and do the same thing ratio * backgroundImage.getHeight() and that will scale it to the portion of the screen size.
Hopefully this will explain it
Now heres a sample of the code to show where everything goes (you can also put the initFrameParams() method outside the class file to make it easier to use everywhere else.
This is only a small part of the total code but it should explain how I got the scler to work.