How can I add images of different dimensions for Splash Screen?
I have watched some tutorials concerning this, but they always use a single image. I believe there ought to be several images to fit different screen sizes and density. How do I go about adding these images?
You need to use configuration qualifiers on your resource folders to indicate when they should be used. You can simply add the folder to the file structure, or use Android Studio's wizard ( New -> Android resource directory ).
These qualifiers can specify size, density, orientation, aspect ratio, etc. For example:
res/layout/my_layout.xml // layout for normal screen size ("default")
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/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density
You can read more about Supporting Multiple Screens from the documentation.
Related
I am a bit new to android and developing an app which has 10 full screen background imageviews . after a while working with the app it force closes because of outOfMemory exception. I got every image in the 720 × 1200 px from photoshop designer. I haven't put different sizes of images in drawable-dpi folders since I am confused how to scale. where am I supposed to put this 720 × 1200 ? in which drawable folder ? Any help or clear explanation would be appreciated . Tnx in advance .
I dont think the solution you are looking for is to use the different drawable resource folders for different screen densities but instead you should check this link: https://developer.android.com/topic/performance/graphics/load-bitmap.html on how to load the bitmaps more efficiently by downsampling before you load them into the Image View and by making sure you release any bitmap that isn't being used any longer.
You have to create different dimen , layout , images and icon files to support all devices.
changes in screen density.
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
Make this layout files, so that it will be same for all devices.
Give padding ,margin ,font and all properties as per devices.
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 Layout ,
res/layout/my_layout.xml // layout for normal screen size ("default")
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
For Images
res/drawable-mdpi/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
For Icon
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density
For Launcher icon
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)
Checkout Dimension and
Supporting Multiple Screens Official Documentaion.
For example, the following application resource directories provide different layout designs for different screen sizes and different drawable's. Use the mipmap/ folders for launcher icons.
res/layout/my_layout.xml // layout for normal screen size ("default")
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/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density
You can use Material design icon plugin which will help you work with any icons provided by Google : Google material-design-icons and with every resolution.
I have PSD, resolution of that is 1080X1920, it contains a Dot image whose resolution is 22X22.
I have cropped that image and put it in my res folder.
My question is how would Android know that the image is for 1080X1920 screen. It would open the same image bigger in small screen and smaller in 2560x1440 resolution.
Is there a way other than putting different images for each screen sizes to tell android to use the image for specific screen size and scale for other screens
use directly https://romannurik.github.io/AndroidAssetStudio/
For example, two devices that both report a screen size of normal
might have actual screen sizes and aspect ratios that are slightly
different when measured by hand. Similarly, two devices that report a
screen density of hdpi might have real pixel densities that are
slightly different. Android makes these differences abstract to
applications, so you can provide UI designed for the generalized sizes
and densities and let the system handle any final adjustments as
necessary
You have to create different dimen , layout , images and icon files to support all devices.
changes in screen density.
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
Make this layout files, so that it will be same for all devices.
Give padding ,margin ,font and all properties as per devices.
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 Layout ,
res/layout/my_layout.xml // layout for normal screen size ("default")
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
For Images
res/drawable-mdpi/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
For Icon
res/mipmap-mdpi/my_icon.png // launcher icon for medium-density
res/mipmap-hdpi/my_icon.png // launcher icon for high-density
res/mipmap-xhdpi/my_icon.png // launcher icon for extra-high-density
res/mipmap-xxhdpi/my_icon.png // launcher icon for extra-extra-high-density
res/mipmap-xxxhdpi/my_icon.png // launcher icon for extra-extra-extra-high-density
For Launcher icon
36x36 (0.75x) for low-density
48x48 (1.0x baseline) for medium-density
72x72 (1.5x) for high-density
96x96 (2.0x) for extra-high-density
180x180 (3.0x) for extra-extra-high-density
192x192 (4.0x) for extra-extra-extra-high-density (launcher icon only; see note above)
Checkout Dimension and
Supporting Multiple Screens Official Documentaion.
Android Studio has a plugin called "Batch Drawable" install in your Android studio. This help to create images of different size.
Steps To import:
File-->Settings-->Plugin-->Browse Repositories-->Click install button.
Restart your Android studio, then you will be able to find "Batch Drawable" inside the file menu of Android Studio.
Link: https://github.com/winterDroid/android-drawable-importer-intellij-plugin
There is no more you have to do, just put the different resolution files into different drawable-xxx file is okay. Remember that all the pics MUST HAVE the same name but Android will not automatically to match the screen size for each pic is the file name is not matched. Good luck!
put largescale image in drawable folder.
I am new to the Android development environment.
I would like to have my app designed for multiple phone screen sizes and resolutions.
If the design for all the screens remain the same, will I be able to use one XML layout for the design with the dimensions specified in "dp" and "sp".
Will android automatically scale the dimensions and font sizes for each phones(ldpi, mdpi, hdpi, xdpi, xxdpi, xxxdpi) automatically? Or do I have to create separate layout files for each of them with the respective dp/sp values?
Also, I hope if I put images for each dip in their respective folders, android would pick it up by itself.
Create layouts for screens like this:
res/layout/my_layout.xml // layout for normal screen size ("default")
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/graphic.png // bitmap for medium-density
res/drawable-hdpi/graphic.png // bitmap for high-density
res/drawable-xhdpi/graphic.png // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png // bitmap for extra-extra-high-density
For Multiple screen support do we need different layouts for each screen which goes in hdpi, ldpi and mdpi folders, I read this on android site, but not sure how to implement this one.
Thanks
Max
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
This information are already given at Android developer site: http://developer.android.com/guide/practices/screens_support.html
Alternative drawables => Screen densities:
Screen resolution (screen density) does affect the appearance of components. To support different screen densities, similarly to the solution given by Ash, have the following folders:
res/values-ldpi for low-density (ldpi) screens (~120dpi)
res/values-mdpi for medium-density (mdpi) screens (~160dpi)
res/values-hdpi for high-density (hdpi) screens (~240dpi)
res/values-xhdpi for extra high-density (xhdpi) screens (~320dpi)
res/values-nodpi for all
Let's assume that you have a default, good-looking layout in the layout folder. In most cases, Android will be able to adjust it properly. In my practice, only large screens require a new layout parameters.
To avoid layout duplication, we use the following layout structure:
res/layout/foo.xml -- layout file
res/values/foo_styles_default.xml -- default styles (component sizes, margins, etc.)
res/values-large/foo_styles_large.xml -- styles for large screen
res/values-xlarge/foo_styles_xlarge.xml -- styles for very large screen
Screen-size-dependent parameters in the 'foo.xml' layout are set via the 'style' attribute, thus allowing us to avoid creating multiple layout files.
As per my observation most of screen will work for different screen size. Please test for app in different screen sizes and if you find issue than place layout in specific folder as diffined above.