Scaling live wallpapers for Android

I am learning how to make live wallpapers, but I have a dilemma. I'm sure everyone who starts, too.

There are so many resolution screen sizes, how can I just make one set of illustrations to scale in the code for all versions? I know that this was done, since I saw images in apk for many of them, and they get scaling.

If it was just one image that did not need any positioning, it would be easy, but my problem is that I need to get a background image that is scalable for all devices, I also have animations that fit into a specific the x and y position on this background image to match, so that it looks like an animated whole background, but only parts of it (my way of staying away from 300 images frame by frame is live wallpaper).

Thus, the background image needs to be rescaled, and the animations must also be scaled to accurately indicate the percentage as the background image, and they need to sit at a specific x and y position.

Any help would be appreciated so that I can do this.


I'm tired of several things, I decided that I would do the scaling for the whole example: int scaler; then in onSurfaceChanged scaler = width / 1024; // if the larger image is 1024. this will give me a ratio to work with everywhere. then scale accordingly using scaleBitmap, multiplying the scaling by the height and width of the image, and also use the same scaling device for an example of placing an image x, say, at 50, scale it using the same thing x = scaler * 50; which should take care of scaling and positioning, just translate all this into java - the next lesson, since I'm new to java, I used the program for flash and php, but these are very different things, get used to it a bit, The next thing is how to pan the width, when you move the screen from side to side, how to make the image display the next puzzle that I figured out. Now it just shows the same width, despite the fact that the width is twice as large as the surface shows. If you have an answer or somewhere, I can find out information about this, which will be very appreciated.

+3
source share
2 answers

Well, um, all I can say is "Welcome to the real world." You get the screen sizes passed to you through onSurfaceChanged, and yes, it is your task to figure out how to scale everything based on this data. That's why they pay us a lot of money. :-) You will want to make sure that your resources are large enough to fit the largest display that you intend to support, so you will always reduce things (which distorts much less than expanding things).

Suggest starting with “best practices for screen independence” here: http://developer.android.com/guide/practices/screens_support.html

Further comments in your request for further assistance ...

  • You cannot (necessarily) scale your work using just the width, because you need to maintain several proportions. If the proportions of the screen do not correspond to your works, you must decide whether you want to distort your work, leave empty spaces, etc.
  • I am not sure how to interpret your problems going around screen sizes. Most of us put all of our active code in one engine class, so our methods can exchange data through private variables. For example, on Cube wallpapers in the SDK, onSurfaceChanged () sets mCenterX for later use in drawCube (). I suggest starting with a similar, simple approach.
  • Scrolling processing requires some “intelligence” and careful evaluation of the data that you get through onOffsetsChanged (). xStep indicates how many screens your trigger supports. Typically, xStep will be 0.25, indicating 5 screens (i.e. xOffset = 0, 0.25, 0.5, 0.75 or 1), but it can be any value from 0 to 1; 0.5 will mean 3 screens. xPixels gives you an idea of ​​how much the launcher “wants” you to move your images based on the screen you are on; usually you should respect that. On my phone, the launcher “desires” virtual wallpapers with two pixels of the physical screen, so each scroll should only shift things by one quarter of one pixel of the screen. All this and much more is described in http://developer.android.com/reference/android/app/WallpaperManager.html This is not an "easy" coding - applications are simpler than wallpapers. :-)

Good luck ... George

PS I'll add one more thing: somewhere along the line you might want to get the “desired minimum width” of wallpaper required by the launcher, so you can clearly understand that virtualization is implied in xPixels. For example, in my kernel constructor, I have

mContext = getApplicationContext(); mWM = WallpaperManager.getInstance(mContext); mDW = mWM.getDesiredMinimumWidth(); 

My device has a width of 320 pixels; I get mDW = 640; when I scroll the screen from screen to screen, xPixels changes to 80 every time ... because four scrolls (on five screens) should double the number of images detected (this effect is called “parallax scrolling”). On the right side, xpixels is 0; the center (of five) partitions has xPixels = -160, etc.

+12
source

I used this piece of code to scale a single image to fit different screen sizes.

 Bitmap image1, pic1; image1 = BitmapFactory.decodeResource(getResources(), R.drawable.image1); float xScale = (float) canvas.getWidth() / image1.getWidth(); float yScale = (float) canvas.getHeight() / image1.getHeight(); float scale = Math.max(xScale, yScale); //selects the larger size to grow the images by //scale = (float) (scale*1.1); //this allows for ensuring the image covers the whole screen. scaledWidth = scale * image1.getWidth(); scaledHeight = scale * image1.getHeight(); pic1 = Bitmap.createScaledBitmap(image1, (int)scaledWidth, (int)scaledHeight, true); 

Make sure that the edges do not contain vital information, as it will be reduced from the image at some screen ratios.

-1
source

All Articles