what is the best practice to set image size for banners and products in E-Commerce/Shopping android application? and what are the ideal image sizes for the product and banners so that it can be responsive for all screen sizes?
Actually there are different ways you can handle this:
Use a high-resolution image file put it into drawable-nodpi and resize that based on your screen density. (I recommend using Glide, but Bitmap and BitmapFactory consist of methods handling resizing and loading bitmaps)
Pro: A single image file can be easily scaled
Con: It can lead to OutOfMemory if not handled correctly.
Put your images into different density buckets MORE INFO. The image files should be based on common pixel densities that phones are manufactured base on e.g. Full-HD (1080x1920) or HD resolution.
Pro: It's less work for OS and even your own coding
Con: It's more work to design image files
Related
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.
When dealing with different screen sizes I use like 3 packs of assets for SD, MD and HD phones / tablets.
But doing this is kinda annoying, and makes the APK bigger.
I want to use just the biggest pack that I want to use, like HD.
But if someone got a 3.2" phone I don't want to render a 1280x768 background on 320x480 phone..
So i'm just wondering..is possible with libGDX to resize a Texture ?
I don't mean resizing like, drawing with a specific size..I mean, in Texture Packer GUI I can add the biggest assets pack and choose to export also HD or MD pack..
Is possible to resize a Texture in runtime?
So if I play my game on a small phone, the textures will be smaller in size.
I hope you guys understand what I'm trying to say.
Using extra storage space on the low-end phones is probably the best bet. The alternatives are less attractive:
Scale the images down when you load them. This will lengthen load times on an already under-powered phone. The scaling will have to be done on the CPU, as the GPU may not support textures that are a multiple of screen size. Plus you'll need to load these large images into memory, which will tax a small phone even more. (You could do this once and cache the results, so you don't penalize every startup but then you might as well just put the files in the .APK) (You could chop the HD image into parts to avoid overwhelming a low-end phone, but that just increases the startup latency even more.) If you still want to try it, with LibGDX you could use a FrameBuffer to create a low-resolution image at run-time from a higher-resolution one.
Scale the images down when you render them. This is unlikely to work reliably, and requires a significant memory footprint to keep the images loaded.
To get a real handle on what you are optimizing here, try building your APK with all the resolutions and then again with just the HD images. I bet the difference isn't that big (the low-end images are, by definition, not that big relatively.)
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.
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.