View image in different resolution screen? - java

I have to put a picture in my application. Not to make her see evil on Android devices with different resolutions is enough to put it into different folders (mdpi etc.) or are there other things to do? What is the resolution for each folder?

Check out the Android developer guide here to see some really good info on supporting screen sizes.
One approach is to use the different resource/drawable folders you have alluded to (ldpi, mdpi etc.), which are referenced as follows:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
As I mentioned, there are a number of other ways to handle screen resolutions and I would suggest you find the one that suits you best (check this one out!).
Place the different image sizes in the different folders with the same name, and when you reference them in code, Android will choose the best match.
Best of luck!

Consider MDPI images as baseline following are the resolutions that should be:
Folder Image ratio size example
ldpi - MDPI x 0.75 - 75px
MDPI - 100 - 100px
HDPI - MDPI x 1.5 - 150px
XHDPI - MDPI x 2.0 - 200px

Related

LibGDX different assets for different resolutions like Android

I have a game developed natively for Android, and now my users also want an iOS version. I thought LibGDX would be the better choice because it'll let me reuse Java code from the game, and also I already have some experience with it.
In my game I have different image sizes for different device densities (in drawable-hdpi, drawable-xhdpi and so on).
So, my question is: how can I achieve the same, but using LibGDX (also taking care of the new densities required by iOS device resolutions, if any change is required)?
Thank you.
Yes you can achieve the same, but it wont be automatic like on Android unless you write some native code as well. I have found that the best way to manage it is simply to do it yourself:
1) When your app starts you can get the screen size and density using Gdx.graphics.getHeight(), getWidth(), Gdx.graphics.getDensity()
2) Depending on the size and density you can change the location path to the correct folder where your assets should be loaded from.
3) Now when any asset loading code is run make sure that it uses your pre-set path from the step above, so that you get the correct assets for that display size/density.
Most of the time you can use the largest image and use `Viewports' to handle resolution and aspect ratio for you. The larger images will be scaled down and this will result in some loss of detail of course.
Viewports will automatically scale the size you want to show of your game world to the screen it displays it. For example FitViewport(100, 100) will create a viewport that shows 100 x 100 "game units". If you would play this on a 1920 x 1080 device it will scale that 100 x 100 game world to a 1080 x 1080 area and leave an empty bar of 840 x 1080.
The size of the game world has nothing to do with pixels. You could create a enemy with the size of 0.5f x 0.5f world units and give that a texture of 256 x 256 pixels. Your viewport scales this for you to the correct size.
Unless you want a pixel perfect game this should be good enough. On some bigger screens but low resolutions devices you might get some minor artefacts due to filtering, setting the filtering for your textures Texture.setFilter(TextureFilter.Nearest, TextureFilter.Linear) might fix some.
All I ever think about when designing graphics are the pixels in my art should represent roughly or at least 1 screen pixel. Usually I just draw pixel perfect for HD and it looks fine on a 800 x 480 screen. If you want to squeeze out a bit more performance you could use MipMaps, I think TexturePacker generates them automatically with the right Filter settings but I have no experience with them.
This can be done using
com.badlogic.gdx.assets.loaders.resolvers.ResolutionFileResolver.
Here is javadoc for it.

Android Studio - pixel sizes for different dpi

I've read the posts but I still do not understand how to convert my image to dpi.
I have a 2689x1900px image. I have created the drawable-hdpi, mdpi, xhdpi, xxhdpi and xxxhdpi folders.
I know that I need to insert the images there (same name) but I don't know to what pixel size do I need to convert. I'm using photoshop.
Can someone please explain the process of scaling and use my example (2689x1900) ?
Let's assume that 2689x1900 is your 100% image, the biggest one. The biggest density is xxxhdpi. So, xxxhdpi is a 100% density.
Next, we need to calculate the smaller sizes:
xxhdpi is 75% of xxxhdpi, so it is 0.75 * (2689x1900);
xhdpi is 50% of xxxhdpi, so it is 0.5 * (2689x1900);
hdpi is 37.5% of xxxhdpi, so it is 0.375 * (2689x1900);
mdpi is 25% of xxxhdpi, so it is 0.25 * (2689x1900)
You can find more on that topic in Supporting Multiple Screens.
Note though that your image size slightly differs from the mostly used xxxhdpi screen resolution, 2560x1920, and you may want to adjust the size before scaling so that the images will fit perfectly into different screen resolutions.
first of all, reducing the size of the image in photoshop can cause pixellations. i suggest you to use inkscape or any other vector graphics editor.
then for full screen image
mdpi - 1 (360x640)
hdpi - 1.5 (540×960)
xhdpi - 2 (720×1280)
xxhdpi - 3 (1080x1920)
xxxhdpi - 4 (1440×2560)
these are the ideal sizes of the image.
the integers represent the scaling factor. if you want to maintain the aspect ratio of the image, then select the nearest image folder and scale.it using this factor.
more details here https://developer.android.com/training/multiscreen/screendensities.html#TaskProvideAltBmp

Android scale background image in LinearLayout [duplicate]

The designer has given me a background to include in my application. It has a lot of detail in it, so when trying to create a 9-patch image, it got blurry.
So, deciding to have a background to all major screen densities in Android devices, what should be exactly the background image size?
For example:
ldpi - 200 x 200
mdpi - 300 x 300
hdpi - 400 x 400
Is there any standard I should follow?
Many thanks,
Felipe
generally, it could go like this:
ldpi: 240 * 320 (small)
mdpi: 320 * 480 (medium)
hdpi: 480 * 800 (large)
but, it won't cover quite a few possibilities regarding devices with 480 * 854 screen resolution, or newer devices with 720*1280..
you have 2 options:
1) try to design a new background that can be used as .9
2) try to create multi-layer drawable
- the drawable would consist of image which is in .9 format, and all the details that are "glued" on it
the second approach requires quite a work from your side. Read about layered drawables here:
http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
xlarge screens are at least 960dp x 720dp.
large screens are at least 640dp x 480dp.
normal screens are at least 470dp x 320dp.
small screens are at least 426dp x 320dp.

Folder name for 7" hdpi tablet Android

I have Tablet with 7" screen (600×1024) with hdpi (240 dpi classification).
I have created folder layout-sw600dp. But it's not working in this resolution tablet.
Its working fine with 7" screen (600×1024) with mdpi (160 dpi classification).
Which folder should I create for 7" (600×1024) tablet which has hdpi (240 dpi classification)?
It depends from the Android API version you're building against, like mentioned here:
... However, this won't work well on pre-3.2 devices, because they
don't recognize sw600dp as a size qualifier, so you still have to use
the large qualifier as well. So, you should have a file named
res/layout-large/main.xml which is identical to
res/layout-sw600dp/main.xml. In the next section you'll see a
technique that allows you to avoid duplicating the layout files this
way.
You should also take a look here:
Preparing for Handsets
and
New Tools For Managing Screen Sizes
Make Your Layout like this:
res/layout/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
For TAB:
For example, if your application is only for tablet-style devices with a 600dp smallest available width:
<supports-screens
android:requiresSmallestWidthDp="600" />
I have Tablet with 7" screen (600×1024) with hdpi (240 dpi classification) which is comes under the Normal Screen see my screen shot.Its working fine with 7" screen (600×1024) with mdpi (160 dpi classification) which is comes under the large screen.
For Tablet .
MULTIPLE SCREENS:
For example, the following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for medium, high, and extra high density screens.
res/layout/my_layout.xml // layout for normal screen size ("default")
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
Hope this will help you.
In android, we use resolution in dp to measure the screen size, not resolution in px.
Both of your two tablets have the same resolution in px, but their resolution in dp are quite different.
600 X 1024px with mdpi = 600 * 1024 dp
600 X 1024px with hdpi = 400 * 682 dp
You use sw600dp as the qualifier for tablet, which will effect the first device but not the second one.
In fact, the second device(400 * 682dp), is much more like a handset rather than a tablet, it should not use the layout for tablet.

drawable sizes for different screen sizes in android

i have a problem in android development that bored me. my problem is screen size and dealing with that. specially i have some problems with images. for example i want to create a background image for my activity that i created in photoshop and my background image contains a "HELLO" word on it. but when i put it on drawable-xhdpi folder, it seems blurry and its not sharp!! my phone is a nexus 4 and according to Google documentation i create background image in 640 x 480 size.
when i create background image in 960 x 720 size it seems better but not perfect. in this case my image file size is very high!
but what is the standard way for this? please help me to solve this problem for ever. i read google documentation but its not solve my problem!
http://developer.android.com/guide/practices/screens_support.html
You should usually avoid creating images for certain screen sizes to make them background, because there are thousands of different devices and you would have to create dozens of such images.
The first thing you need to be aware of is screen density.
Generally you create 3 to 5 images when not even looking at screen size: low (120 dpi), medium (160 dpi), high (240 dpi), extra high (320 dpi) and 2*extra high (480 dpi). These go into drawable-Xdpi folders, where X is one of l, m, h, xh, xxh.
Next thing when you want to have bigger images on bigger screens (bigger phones, small and big tablets), you may want to put images to folders like drawable-sw600dp-Xdpi. This is not a case for your phone.
Nexus 4 is a xhdpi 640x384 dp device, but you should not treat it differently than Samsung Galaxy S2 (hdpi 533x320 dp).
Create an image of smaller size for both phones and center it horizontally. E.g. 320x100 px for mdpi, 480x150 px for hdpi and 640x200 px for xhdpi (your phone).
the screen resolution for Nexus is 1280x768 (http://www.google.com/nexus/4/specs/), resize the image to this resolution. In especial consideration some images can't handle the resolution and the image became disproportionately.
for interesting
resolution calculator:
http://members.ping.de/~sven/dpi.html
This is problem of Android Fragmentation and you just cannot deal with it perfectly as there is a several hundreds different devices. As colleague above wrote Nexus 4 has resolution -1280 x 768 so for sure res of image as equal as 960 x 720 is good choice. I'm even surprised that google suggest 640 x 480 for xhdpi, it's definitely too less.
So as I said you are not able to make perfect looking graphics for all existing devices. You should choose the most popular devices from every screen category(xhdpi,mdpi,ldpi ... etc) to cover the most important market share.
With 1600+ android models even after they are categorized in few Screen size and a few DPI's its very difficult to manage layouts.. i suggest that you just concentrate on designing layouts w.r.t to screen size and then create views as Resizeable Views to neglect density effects.
Once you have created your layouts Resize the Views .. You can create a Custom View or resize on its onMeasure();

Categories