I have three general questions regarding android's drawable folders.
Do i put different sized images in each of these folders, or will the images automatically scale themselves? As in, does android decrease the quality of the .bmp files automatically if placed in these folders?
When using the android design preview screen, will the appropriate image from the appropriate drawable folder be shown? If I have to make different sized images for each folder, I want to ensure that what i'm seeing in the design preview matches what is shown on other devices.
Lastly, do the drawable folders, if used, help to avoid the issue with failing to allocate memory for drawables on devices? I have had to scale my images down, and yet my college's phone still cannot allocate enough resources.
I couldn't find answers to these specific questions anywhere, so i'd really appreciate the help with these!
1) You don't need the different folders if you will put the same things in those folders. The designer/developer puts the resources that most adapt to that configuration.
2) You can select what kind of device you're previewing the design with (resolution and dpi), on the design tools. It will attempt to load the appropriate resource for that configuration.
3) Loading smaller images into memory may be helpful, as well as resizing them before displaying them (libraries like Picasso can do this out of the box), or you could be looking at a leak of some sort.
About your first question, you should create four different drawable folders in app>res in order to provide different devices (with different screen sizes and densities) more convenient images.
/drawable-ldpi For low density screens.
/drawable-mdpi For medium density screens.
/drawable-hdpi For high resolution screens.
/drawable-xhdpi For extra high resolution screens.
Android does not decrease the quality of .bmp files when they are allocated in those folders. You have to fill each folder with the correct sized images.
About second question, I am not sure whether the android design preview screen uses the correct images or not, but in a real app running on a phone, it will.
And third question: sorry, but not.
Good luck!
Ad 1 I always find it really helpful to load drawables to my project using Android Drawable Importer plugin. It will take care of loading appropriately-sized image into appropriate drawables folder.
Ad 3 If that works for you, maybe try loading images from server using tools like Glade or Picasso? That way you don't clutter your app with unnecessary resources, making it too heavy data-wise. Use a local drawable as placeholder only, in case there's no internet connection.
I'd also recommend using .png over .bmp format, .png are lossless and compressed, meaning your images can get significantly smaller while not losing quality.
You have to put images in different folders as per the image size. it will not generate automatically.
You can not select image for that screen. you can just select different screen sizes android studio will automatically use proper images for that.
For memory issue you can add this line in manifest :
android:hardwareAccelerated="true"
Related
What is the best practice to store resources in libGDX library. I'm know that I can use AssetManager and also e.g. I can link the resources from android folder into iOS, but I dont know how it will behaviour on multiplatform devices. The resources are scale according to screen size/operating system, or I need to manually set diffrent size or resulution in each platform resource folder.I want to avoid any ovelaying or stretch behaviour.
There are many ways to go about this and there is no "best" solution. However if you do already build for android just use the android assets folder. This is the default and will be used for other builds (due to the default libgdx project configurations).
The resources only scale if you tell them too. You can choose to use a viewport (a fit/fill viewport will not stretch but can add black/background bars that do not have the default aspect ratio). But you can also choose to implement screen dependency yourself by using the aspect ratio and the scale.
For instance:
A 1080x1920 mobile phone vs a 1440x1920 tablet
If you use a fit viewport you will have unused space on the tablet. if you use a fillviewport you might lose stuff on the phone. But if you take the phone as a default aspect ratio and calculate the width offset for the tablet (1440-1080/2) you can use this value to choose to put actors/sprites on the same location as on the prone (by using this offset) or relative to the screen edge (by using the screen size). I personally use this to place the UI relative to the screen and the game itself the same as on the phone. You can even choose to use a different layout depending on the aspect ratio.
Do note that in this way you will also have to calculate a global scale and use this everywhere in your application. This can be tedious to implement but gives you much more control!
So if you have a simple game and you don't care about tablets or different screen sizes I suggest you start with a fit viewport.
p.s. Not sure what you mean by "multiplatform devices", but as I said, the default libGDX setup does the heavy lifting here, so I suggest you use it!
I have a little problem with an app I'm designing. I need to be able to open a high-res image (stored in the assets folder of the project), with the android gallery. I have tried many things, like put it in the drawables folder and retrieving the Uri (which gives Out of Memory error). I need to be able to have that high-res image without any type of compression because the user will need to zoom in a lot.
Any idea is welcome, thank you everyone in advance!
You have to copy your image from assets folder to external memory for the Gallery app being able to display it.
The android application is have a strict restriction of using dynamic memory, it is 16 mb. So if image is larger then at least 15mb trying to load it into memory will undoubtedly encouner with OutOfMemory error.
Use this library https://github.com/davemorrissey/subsampling-scale-image-view , which is designed, as it seems, exactely for your needs. As follows from description, the main concept is to load large images partially, just a part for current displaing.
i want to clear my all doubts about android multiple screen support.
i have searched a lot but not found any solution for it.
i can clear my question by giving an example.
first i have a screen 480*800 and i have all image resources used in this screen with relative to this size(480*800). and i have created my layout using wrap_content attribute.
so i want to ask where i put these image resources in drawable hdpi or mdpi or ldpi or x-hdpi.
for example if i put these in drawable hdpi then what about other folders and other screen sizes.
i have read all Article on developer's website but i didn't found any solution.
or where could i found a complete tutorial whit handling this issue.
Thanks in advance.
PUT THOSE FILES WHICH YOU WANT TO USE FOR ALL TYPE OF SCREEN RESOLUTIONS IN drawable FOLDER , IF YOU WANT TO USE PARTICULAR SCREEN SIZES THE PUT IN hdpi or mdpi or ldpi or x-hdpi , u have to create a folder "drawable" for all common sizes .
480 * 800 is a mdpi device. You can can put these image resources in drawable-mdpi if you want the device to auto adjust for smaller and larger screen sizes. If you want these images to be of maximum size you can put it in drawable-xhdpi.
If not i.e. if you want same image to be used in all the screen sizes then you can simply put in drawable folder in resource.
For more information you can check this :developer link
Is this done by creating identically named xml files and placing each in drawable-ldpi drawable-hdpi folders? At the moment I am doing this but only different images are being used. No matter how I change the ldpi folders xml the hdpi's is used.
Am i doing something wrong? Or can I force the emulator to update (I am pushing the current apk to it) ?
The folder modifiers -ldpi, -hdpi, etc., can be used for other resource folders besides drawable. You can also have layout-ldpi, layout-hdpi, etc. Each would contain an identically named layout xml file, each with different xml (or not).
Be aware that the logic used in the emulator to decide what folder to use is rather complicated and depends on both the emulated dpi of the device and the scaling factor used for rendering the emulator screen. You may think you are emulating an ldpi device, but the emulator may still be deciding to bind the hdpi resources.
I have been developing Android application since 3 to 4 months. I am naive, But pretty much exposed to all of the fundamentals regarding application development on android. However I found really painful while developing application with lots of images, By saying images I mean one of my application has around 10 to 13 images(Small enough to accommodate screen size). The problem is I have to make different copies of it by making,
HDPI - High resolution support
MDPI - Medium resolution support
LDPI - Low resolution support
I have come up with an idea,
IDEA : My idea is to actually have only MDPI images in drawable folder, When my
application will installed first time, I want my application to detect what type of
resolution is supported by device? After knowing which resolution is supported one of my
built in method will either use a MDPI version(images), if handset supports it or else
it will scale up or scale down my images and stores into internal storage for future
reference. When user uninstall my application I will remove these images from internal
storage.
Now this idea has raised a question,
Question :
Whether this idea is feasible? and Programatically possible?
If it is, Should I be really concerned about one time computational overhead?
Is there any mechanism(third party) which can ease my problem? (I hate photoshop and scaling up and down all those images)
Any expert help or guidance will be a big favour!
Thanks in advance!
Krio
I dont really understand why you would do this. The system already basically does this for you. You dont have to specify different images for different display densities, the system just gives you the opportunity to so you can make your app look its best. If you only supply a single image the system will scale it appropriately for you based on the density of the handset.
As for help with scaling the images yourself for packaging, you could look at image magick. This is a powerful scriptable image manipulation tool. You might need to spend a bit of time getting up to speed with it, but I am sure you could write a script that you could reuse for all of your images after that to convert high dpi images to lower dpi ones by scaling down.
Take a look to this article. It describes how android handle directory names for resources. Also take a look a look to this - how android choose the best match for directory name. If you want to use the same resource for all dpis just place it in the default drawable folder.