I am developing for the Android. When I create icons in Photoshop (and convert them to PNG), they appear larger and stretched within my Android application. The emulator that I am using is medium density. Does anyone have some tips for how I can create my icons in Photoshop so that they appear normally on the Android?
Thanks!
The dpi of the PNG isn't relevant in this instance, only the actual pixel size. How are you displaying the images? If you're using an ImageView, try setting android:scaleType="none". If you're setting its width and height with wrap_content it shouldn't matter, but it's worth a try.
Also, if you're accessing them from the drawables folder, try placing them under a new folder called drawable-mdpi. Android should detect that the emulator is set to medium density, and automatically use the resources from the mdpi folder if they exist.
PNGs can store pixel size information (dpi). That's probably why you see the image larger and streched.
Check Photoshop's image size options, if necessary fix the print sizes so aspect ratio is conserved.
I also have this problem. I don't know why. I am using Mac. The png file produces by it is extremely large. For example, the normal size should be 8kb, but it's size is 48kb. If a use other editor to edit & save them, the size return OK. Seems that ps is saving some extra info into the png file.
Related
Before, I did this by just having the different versions of the images within their respective res/drawable folder.
thanks
i want to fill the available space while retaining the scale. i want the image to be able to fill 92x92.. or 144x144.. and so on depending on what the phone needs visually..
I've tried different combination(min/max height/width)s but nothing is giving me any consistency
I know I need to use different DPI for images and all graphics stuff, but I just don't understand if I have to create the different drawable folders by myself or if there's a proper way to do it, and plus, what to use them for.
For instance I need to add a wallpaper, where should I put it? And of what resolutions? What are the pixels needed for each?
Tried to read the Google page about this, but didn't get much, thank you!
I have to create the different drawable folders by myself or if
there's a proper way to do it?
Assuming you're using Android Studio:
what to use them for.
from http://developer.android.com/guide/practices/screens_support.html:
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
In that page you have documentation for screen sizes and densities.
Basically, when you put, let's say, an image in an activity, it will render according to the device's density corresponding folder.
a wallpaper, where should I put it?
The best is to have an image for each density, but if you don't have those provided, you can put it in the drawable folder, without any density qualifier, which means that your resource is the same for every screen density.
For a quick way of knowing your device screen stats, download ScreenInfo.
"...I just don't understand if I have to create the different drawable
folders by myself"
no, you don't have to, but you can.
"... if there's a proper way to do it"
If you right click on res then select new then select Image Asset, Android Studio has an Image Asset tool that guides you through the whole process. This is how you import various UI elements in their correct dpi and densities.
"... what to use them for"
This is upto you. But if you set an ImageButton to an drawable with various drawable resources for different screen dpi, the correct dpi drawable will be chosen according to the device's screen dpi when the app is running.
"wallpaper..?"
Put that in drawable-nodpi or just the regular drawable
I'm new at Android Game Development I already read (Dummies Android Game..., Sams Teach..).
I want to draw now several images (tiles) to create my map, but I also want that they are automatically scaled to the device screen as good as possible. At the moment I just know how to use images from folder drawable but they are not scaled to the screen...
I already saw some examples where they use xml files to get to images over R.id.... but for this I must use the xml as layout in the code and can't use something like this or?
//create the view object
view = new SurfaceView(this);
setContentView(view);
view.setOnTouchListener(this);
I'm a little bit confused... :(
How do other Game Programmer scale their images to the different device screens?
I would be very thankful for some examples!!!
You could let android scale the images for you automatically, but of course, the quality might not turn out the way you want, but it is less work on your part. If you want more control over the scaling of your images, the only choice is to manually create them and put them in their respective folders including the default folder (drawable folder without subfix), drawble-mdpi is for medium Dot-Per-Inch devices, such devices as 320x480 screen.
drawable-hdpi is the drawable folder for devices with a high density screen size such as 480x800 or 480x854 depending on the screen sizes as well. I am going to give you the threshold by which you use to tell if it is mdpi or hdpi so on
1.mdpi: 160dpi (dpi = Dot Per Inch, it is different from dp or dip which stands for density-independent pixel)
hdpi: 240dpi
xhpdi: 320dpi = 2 times mdpi, this includes devices such as galaxy s4 with a screen resolution of 1080x1900 depending on the screen sizes as well, you kinda get the idea of how big xhdpi is.
xxhpdi: 480dpi, this one is newer but you can be guaranteed xhdpi images will scale up to fit xxhdpi very nicely, generally, you dont need to create graphics assets for xxhdpi, xhdpi is good enough.
One rule you should remember is that, you should create images for xhdpi devices and scale down accordingly, not the other way around.
As for R.id.., the part after the "R" is called the resource type you want to reference, if it an id you put R.id, drawable use R.drawable, as in the setContentView() method, you have R.layout because you are referencing a layout resource. I hope this helps you a little
When you use xml for drawables these are located to the drawable/ folder and not the layout/ folder.
In order to use them you call R.drawable.name_of_your_drawable not R.id.... nor R.layout.....
Another way to avoid blurring in larger screens is to provide different resources for different screen dpis for this option you have to place your drawables to
drawable-mdpi/
drawable-hdpi/
drawable-xhdpi/
etc
Note: that when you use multiple folders each drawable must have the exact name in all folders and the system decides which to pick.
Ive read Android documentation on the subject of supporting multiple screen sizes but I just cant seem to wrap my head around it. I know qualifiers need to be set in layout names and android picks the one whos qualifier is closes to the width of the phone.
Im not to worried about tablets at the moment but when I develop for my physical device everything is fine and dandy all in default layout folder: layout/main.xml
But if I test on my friends phone Samsung Galaxy S4 everything is streched in a vertical way. I just dont know where to begin really...
Is there a standard set of folders that I could implement to lay my layouts in and then edit for optimized performance?
http://developer.android.com/training/basics/supporting-devices/screens.html. It's all explained in this tutorial link.
If one layout should support all screens then,
your app theame should be similer for tabs and mobiles
never use fixed values for layouts like (ex:300dp , 15dp), all are wrap , match , fill depends on requirement,
make all the icons, images in 2 or 4 different sizes
NOTE: if you have minor changes for smaller to larger device ui, then in on create get the device height and width , make your changes (images, layout widths etc..) runtime from java
If your app is not similer from small to big devices
Use layout(mobiles) ,layout-large(7 inch tabs) layout-xlarge(10 inch tabs)
Start with device independent pixels (dp) and scalable-independent pixels for fonts (sp)
If something is stretched vertically after that, it probably means it's a background image that's trying to fill up the entire height of a layout (by the way, next time you have a problem, please do post the relevant xml code and dimensions of the image, or at least a screenshot of the problem).
In that case, just use the different size qualifiers to solve your problem (not your density qualifiers). Density qualifiers don't help for widths or heights of bitmaps that are larger than the widths or the heights of device screens. This is just a rule of thumb that you should be aware of.
Use the toolbar select box in the layout designer of Android Studio/IntelliJ to quickly test multiple device screens all in one go. This is the fastest way to do it. Do not use Eclipse for that, its ADT layout designer doesn't have that capability (at least, not the last time I've checked). Even if you use Eclipse most of the time, it's worth using Android Studio/intelliJ just for that functionality, and then switching back to Eclipse (assuming it's still your favorite IDE after that) when you're done with testing that aspect of the layout.
Also, don't try to do a different layout for each size qualifier that you encounter. Only use different size qualifiers for the layouts that are actually giving you problems. And don't forget that common layout components that don't need to be duplicated can just be abstracted away in a parent layout. And if you can find a way to resolve your specific problem without the use of size qualifiers, that can work just as well. For instance, if instead of using a single image for your background, you could replace it with a larger image that you don't mind getting clipped at different aspect ratios, or replace the background image with something entirely different and abstract (like a solid color, a gradient, a tiling background, a large vector graphic, or a large patch-nine png) that looks ok at different aspect ratios, that could be even simpler still.
At the high level, you just need to take care of these things:
- Better have the images sliced for either XHDPI (720x1280) OR XXHDPI (1080x1920) resolution and keep them in respective folders. XHDPI images into drawable-xhdpi and XXHDPI images into drawable-xxhdpi folder. One set of image slices are enough.
- You don't need to write different XML layouts for the same screen if you are not supporting Tablets (except for very rare times)
- Try to avoid hard coding the android:layout_width & android:layout_height parameters. Use wrap_content, fill_parent OR match_parent.
- Try to avoid keeping any image slices inside simple drawable folder instead keep inside specific drawable folders like drawable-xhdpi , drawable-hdpi etc.
- Try to use, color codes & 9 patch images as much as possible instead of using images for everything which will reduce the build size and also helps in avoiding OutOfMemoryException.
- Inside simple drawable folder, keep all your XML drawables like background of a button with separate images for clicked & focused states etc.
If you follow these steps, you don't need to worry about supporting multiple screen resolutions for most of the cases.
am trying to build android app with a dynamic layout to support multiple screens
am thinking about build all my app for a certain device with a fixed dimensions like Motorola Droid , say that the button will be 50 width 50 height
and after i finished all the app , i will reedit the sizes of elements to be a ratio betweetn the right place of them and the dimensions of the new device
also Drawables will be Scalable Drawables and i will use only the Drawables folder and remove others :
- drawable-hdpi
- drawable-ldpi
- drawable-mdpi
so i will have only one Drawables folder and only one layout xml file for every activity
and most of my layouts will be hard coded using java
so the question is : is it a true method for development ?!
may be you will ask , why ?
so my answer is , as i think my method is easer than using :
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
The simplest (and probably the best) way to create layouts that support all screen sizes is to use a RelativeLayout.
AFAIK you can manage resoution variation of different devices by keeping the images in drawable-hdpi,drawable-mdpi,drawable-ldpi folder.
then screen sizes by providing different layout for different screen size categories by specifying layout-small,layout-large,layout-xlarge.
also you can increase number of devices supported by using nine patch and relative layout check this google official documentation regarding this topic.
hope this help.
thanks.