Android Supporting Multiple Screens with fixed width icons - java

This may not be explained the best but here it goes.
I have a window of 2 by 2 square icons. I found a custom layout script that spaces these equally on the screen. These 4 icons consist of a square background with a little image and title.
At the moment the width and height are defined in dp. But that stretches or shrinks the text. I am assuming I need to use fixed values. I understand that there are 4 generalised screen resolutions.
My question is, for small I would have to set the width and heights to x and y, but when the screen gets bigger due to larger devices I would have to increase x and y to keep some sort of continuity.
Is there a minimum and maximum width and height of screens for each size? How do other people get around these issues.
Sorry if it is a bit broad and sweeping, but I am new to creating dynamic (ish) displays for multiple resolutions.
Any help and advice will be greatly appreciated.

Google has actually documented this well. When you load your images in your res folder, you will need to simply put high, medium, and low res versions of your file into the file with the same name (but with hdpi and so forth appended to the name of the file). Android will handle which file to choose based on the screen size. I could go through how to do this, but this link covers the details of what I'm talking about in greater detail. Also, check out this question I answered a while back. It has a lot to do with your question.

Related

What width should my images be to be neat on my app?

I have a recycler view on my android app main page that displays a list of pictures and I can't decide which width to give my images so that they are not too heavy but still very neat. (My images take the whole width of the screen.)
I know every Android device has a different format but I need a one-size-fits-all.
I currently have images on my res folder with width 500px (and approx. 350px height). The images weight between 30ko and 100ko. But I must admit they are not very neat ...
So I guess I have to pack pictures with a greater width to gain quality, but I have no idea how much.
How does Instagram does it ? Pictures are always very neat, how do they do this ? What are the characteristics of their pictures ? I guess they weight a ton, no ? (like 500ko per image ?) or am I wrong ?
There are utilities ('Image Optimizers') that shrink jpeg images without any significant quality loss, you can find some of them on Google for manual use.
When showing a lot of images, you can use a library such as Compressor to do this for you. I believe that apps such as Instagram might have their own code but same same. The file sizes are usually 15-300 kb, depending on the 'complexity' of the image.
After spending quite some time testing on different sizes and weights, my conclusion is that 500px wide images are not displayed very well on devices in general when you want to have image that take the whole width of the phone. But you can have light images (between 30Ko and 80Ko).
Below 500px width is not a good idea.
When you go up to 1000px wide images, you get a whole better quality, that gives your app a better look and feel in my opinion. But obviously images are somewhat bigger (between 80 and 190Ko)
When you go up to 1500px wide images, you have to be careful to the weight of the image. I wouldn't recommand having images that weight more than 200 Ko. But at least you got very good quality ... which is something nice :D
I hope that could help

Android supporting multiple screens and standardizing UI, dp scale differs on some screens

We are working on an android app, and we have encountered an issue where devices in the same density bucket, i.e. "xxhdpi" do not all look the same, i.e. the Pixel and Pixel 2. We have a very image heavy UI and are using a Constraint view to organize the placement of several overlaid images. The Navigation drawer at the top of some of these screens further exacerbates the issue, as the margin is thicker with different densities on the same screen size and the rest of the app in squeezed into a smaller frame.
Heres an example of how different the Pixel and Pixel 2 are rendered:
Pixel 2 vs.
Pixel
We have tried making more specific layouts to match more specific ranges of DPI but the simulator groups the same devices together no matter what we try. These are the layout categories we've tried, where sw320dp for example refers to a minimum screen width.
Is there a way to combat this issue with constraint view features such as a constraint anchor or percentage constraints? Alternatively can we more narrowly define our layout categories or do something about the dp scale not being the same for similar devices? We have already consulted this page as well as numerous stack overflow posts: Android's Guide on Supporting Multiple Screen Sizes.
Any suggestions, comments, or specific questions welcome, thanks in advance to anyone who takes the time to read this.
This is my approach for getting the image to be shown completely without cropping on the edges, hope you get some kind of idea from this to tackle your situation.
Problem here is with wrap_content and match_parent, though pixel and pixel 2 falls in same category that is "xxhdpi" for getting the image from density bucket but they have little bit change with their width, pixel: 143.8 x 69.5 x 8.5 mm (5.66 x 2.74 x 0.33 inches) and pixel2: 145.7 x 69.7 x 7.8 mm (5.7 x 2.7 x 0.31 inches)
So I am guessing you probably have match parent for width and image scale type as center crop so image is scaled accordingly zooming in, so because they have different widths they are zoomed in more on one compared to the other.
I had similar kind of situation so what I did was used webview with match parent as width and wrap content as height then I displayed image in the webview
WebSettings settings = webView.getSettings();
settings.setLoadWithOverviewMode(true);
here setLoadWithOverviewMode actually zooms out and fits the image so no matter what you always see the whole image.

Purpose of Virtual width/height in libgdx java

I watched a video by a guy I think is very good with game development, ForeignGuyMike and in his tutorials he uses a virtual width and height and scales it by 2. Here is a screen shot of the code.
I am starting a brand new game and want to know if there is some type of purpose to this. I want to know the pros and cons of this because I can't seem to find where he explains why and where on the internet someone does this. He then multiplies the virtual width and height by the scale for the size of his window. Any help is extremely appreciated.
First go through this article by Xoppa, it should clear your basics. But just to understand by an example.
Say you have a screen of width height = 1980x1020px. Now in your game, you hardcode your character size be 100px which looks fine. But if same game is started on a screen of 1280x720px that character of 100px height will be too big.
One way is you use relative values always. For example, take height of screen every time game runs and set your character height be SCREEN_HEIGHT/10. Now you have to follow this everywhere, set character tail height be SCREEN_HEIGHT/11.5 and so on. This could be hard to handle once your game starts to grow.
But if you create a screen camera of say 20x11(virtual screen size) and set character height be 1.2f then no matter what the screen size be, your character size will always be relative to the ratio of height. Because you are working independently from pixels. Everything is explained in the above article by the way.

Libgdx Pixellated GUI Effect

In LibGDX, I am currently trying to achieve the effect of a pixellated GUI, meaning the buttons are pixellated, like an 8-bit theme.
When I make my GUI elements, such as a TextButton, I am using images that are small, say 34x16 pixels, but I am rendering them on a large resolution like 1920x1080. What is the best way to render such a small image at a high resolution?
My thoughts were to use stage.setViewport(WIDTH,HEIGHT), and set the width and height to a scaled down resolution, so the gui elements wouldn't be so big. This works, however when adding elements things go wrong.
This my stage/table currently, using a scaled down resolution. I am adding widgets using to the table like this:
table.add(playButton);
table.row();
table.add(title);
but as you can see, the table.row() makes a row that is much too large, perhaps a row fit for a larger resolution. Is there any way to change the gap that is made by the row? I would have thought that the gap would be zero, and by using table.add().pad() you could change the gap, but I am not doing any of that.
Any help would be greatly appreciated.
Ninepatch
This is a common issue in all apps. To overcome this, images which can be safely resized in parts are used. they are called ninepatches.
Here is a nice Tutorial about using them in libgdx.
Distance Field Fonts
Although you haven't mentioned it here, you'd also find font sizing (pixellated fonts) as an issue. For that Distance Field Fonts are used.
Hope this helps.
I would say don't worry about scaling them up and making the virtual resolution bigger. If you want to see picture still pixelated when you scale it use Texture filter. For your case you want to use Nearest filter. use it like this:
yourTexture.setFilter(TextureFilter.Nearest, TextureFilter.Nearest);
where yourTexture is the texture that you have all your bitmaps and skin elements on. If you are using texturePacker than you can specify the filter before packing too. Or just open the .pack file and on the top you will see filtering options, and edit those to Nearest.

Android: Scale fixed Layout down

i want to scale my android application, basically i developed it for 800x480 display with a AbsoluteLayout. This is necessary for my Application, i can't change it.
Now the Problem:
When i start my app in the Emulator the buttons disappear and the images are extremly large. I thought android would scale applications with a fixed size down by default, but it does not work. I already tried to manipulate the manifest but this did not work.
I use a ImageView component for graphics.
Targeting Android 2.1
Cheers
Felix
It is definitely not ideal to use AbsoluteLayout. But, if you want to just push through with it, you should switch the units of all your co-ordinates and sizes away from px (pixels) to dp (density independent pixels). You will have to scale all of your existing co-ordinates by a factor of 2/3 to start, since 1 dp = 1.5px at the density that your layout targets (hdpi).
You will need to explicitly specify the sizes of all your images and layouts. If, for example, you had a button that was 30px wide and 120px tall, then it will become 20dp wide and 80dp tall.
Of course, the images won't look great on smaller (mdpi) screens, since they will be scaled to 2/3 size. Also, some devices are fixed to landscape mode, where you will definitely encounter layout problems. So it's not pretty, but it may get you over the finish line, depending on your requirements.

Categories

Resources