简体   繁体   中英

Set screen resolution for canvas/surfaceview

I am trying to create an animation for a mobile phone app in android, and have created an image that is 320pix high. But when he appears at position 0,0 on my Galaxy S3, he's a bit small.... (Portrait mode and landscape). I would prefer to not create large images for such a high resolution, so is there a way to set the screen resolution to something like 640x480 or maybe 1024x768? It seems to be at it's highest possible resolution at the moment.

I am BRAND NEW to Java and android. (.Net background). I am using Canvas and SurfaceView. I'm hoping there is a SetResolution type method... Hope someone can assist.

You cannot change the resolution of the screen easily (if that is what you are trying to do).

So you either need to create a larger picture, or scale it to the required screen size.

You should get familiar with all the density, resolution stuff on Android. I can highly recommend reading the Android Developer Documentation on Supporting Multiple Screen Sizes . It does contain a lot of useful information about that topic.

It also helps you on how Android can resize images for you.

In short some information on how to do it on your own:

You can add a SurfaceHolder.Callback to the SurfaceHolder uses in your SurfaceView . This callback has a method , that is called, when the screen resolution changes. You can create a static class, to which you will pass the new size of the screen. This class can calculate the ratio of the screen, and you could assume that you are working always with a 800x480 screen (or whatever you like). You use a method like double MyCoord.x(int) . You pass an x coordinate -- within your assumed 800x480 screen -- and the method returns the real coordinate on the screen, according to the size, you have passed to your static class, from the SurfaceHolder.Callback .

That would be ONE possibility you have. To find more detailed explanations and more possibilities, you should read the Developer documentation, that has in my opinion, quite good examples on the most topics :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM