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.
Related
I created layout-sw600dp/layout.xml and it was looking great on device A. But on device B this layout has melt and looks bad. I want to know how my layout looks in worst possible case scenario (exactly 600dp width screen)
I want to create emulator with that screen size, so I will 100% sure that my layout will be looking good on sw-600dp+ phones. Do you know what size it is?
Also, I would really appreciate and be happy if you could give me an advice how to support multiple screen sizes in a modern world.
P.S. I have pretty difficult layouts with 40+ buttons
The short answer to your question regarding the type of emulator you'd use for sw-600dp+: a 7" tablet. You can find more information here. The sw in sw-600dp is the smallest width qualifier. It means that it is only mean to be used for devices with 600dp, which is typically 7" tablets.
The longer answer to your question about how to make sure your app look good "in a modern world" is:
Rather than trying to figure out what is the "worst case scenario", you should design layouts for each of the different screen densities and device types that Android supports:
ldpi Resources for low-density (ldpi) screens (~120dpi).
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra-high-density (xhdpi) screens (~320dpi).
xxhdpi Resources for extra-extra-high-density (xxhdpi) screens (~480dpi).
xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi).
Per the Android docs:
To create alternative bitmap drawables for different densities, you
should follow the 3:4:6:8:12:16 scaling ratio between the six primary
densities. For example, if you have a bitmap drawable that's 48x48
pixels for medium-density screens, all the different sizes should be:
36x36 (0.75x) for low-density (ldpi) 48x48 (1.0x baseline) for
medium-density (mdpi) 72x72 (1.5x) for high-density (hdpi) 96x96
(2.0x) for extra-high-density (xhdpi) 144x144 (3.0x) for
extra-extra-high-density (xxhdpi) 192x192 (4.0x) for
extra-extra-extra-high-density (xxxhdpi) Then, place the generated
image files in the appropriate subdirectory under res/ and the system
will pick the correct one automatically based on the pixel density of
the device your app is running on:
res/ drawable-xxxhdpi/
awesome-image.png drawable-xxhdpi/
awesome-image.png drawable-xhdpi/
awesome-image.png drawable-hdpi/
awesome-image.png drawable-mdpi/
awesome-image.png
You would do the same thing for layouts, creating a specific layout for each of the various dimensions (be sure to put the layouts in the right directories: layout-xhdpi, layout-mdpi, etc.). Doing this will allow the device to select the correct image/layout based on the device the user is using.
If you have a 40+ button layout, you would create buttons for each layout using the above method, then create layouts for each device. It's tedious work, but it is the correct way to do layouts on Android devices.
TLDR; read the Android documents around supporting multiple screen sizes.
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.
I'm designing the layout of Music Player. When I'm rendering it with the Nexus 5 virtual device, I'm not facing any problem at all
When I render the image with Nexus 7 it is showing the same image size.
Posting screenshot of my photo too.
Hope to get some solution from you guys.
You have to follow this to support multiple 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.
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)
NOTE: Always try to use SP whenever you deal with textSize, like textsize=12sp
Use predefined textAppearance:
It will set text size automatically as per device density.
<TextView android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView android:textAppearance="?android:attr/textAppearanceLarge" />
Sample usage:
<TextView
style="#android:style/TextAppearance.Small"
android:text="Sample Text - Small" />
<TextView
style="#android:style/TextAppearance.Medium"
android:text="Sample Text - Medium" />
<TextView
style="#android:style/TextAppearance.Large"
android:text="Sample Text - Large" />
Please visit Supporting Multiple Screens
Hi in the below layout icon displaying small and as well as icons not occupying full screen.I want to occupy the icon in full screen and icon should be in bigger size.!
If I am using small mobiles it occupying full screen and icons also displaying correct size.when I am installing my app in this device it's giving two problems.
Can any one help me from this issues.
Thanks in advance
Check the official documentation for explicit information.
Any android phone has one of this six screen densities.
ldpi Resources for low-density (ldpi) screens (~120dpi).
mdpi Resources for medium-density (mdpi) screens (~160dpi).
(This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra-high-density (xhdpi) screens (~320dpi).
xxhdpi Resources for extra-extra-high-density (xxhdpi) screens (~480dpi).
xxxhdpi Resources for extra-extra-extra-high-density (xxxhdpi) uses (~640dpi).
Use this for the launcher icon only, see note above.
Create icons of different sizes for different screen resolutions and put those icons to yourProject/app/src/main/res/drawable-mdpi or -hdpi or -xhdpi or -xxhdip folder.
I believe the issue here is that even though the tablet has high resolution, it still has low density due to its large screen size. So, the tablet is picking the image from low density folder which makes it look small on large scree.
The discussion here sheds some light on the issue. Basically you are required to create separate drawable folders for tablet's width. Ex. drawable-sw600dp and drawable-sw720dp etc.
Refer developer guide for more details.
I want to use background image in my app.But i am so confused about different screen sizes.I found this question:
Android: Background Image Size (in Pixel) which Support All Devices
But in answer he said xxxhdpi: 1280x1920 px but Lg G3 is xxxHdpi and screen resolution: 1440 x 2560
I need a roadmap.How should be my image sizes for all screens ? (mdpi,hdpi,xhdpi etc.)
Android devices' screen sizes in pixels and screen width in inches, can differ significantly from device to device.
To address this issue, google lets you use different resources per size/density category
See here for some more info.
Generally speaking, you must put the largest size image that you want to support for each dpi in the correct folder, and let android do the resizing.
You can also check the imageView's ScaleType attribute to choose how to scale the image to fit the view.
EDIT
the reason to use the different folders and not just one large image is that the larger the image, the more memory it consumes.
For example a 1920x1280 image is nice to have on a 1920 screen, but on a 320pixels screen the extra resolution is wasted and you have a lot of wasted memory used.
An easier way is to include one single image in your drawable directory, then, in the OnCreate function of your activity, create a bitmap to fit the screen and put it in an imageview that has width and height set to "wrap_content".
This should work for any device.
Read this link. In particular, I think what you're looking for is:
To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:
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
and also:
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