If I have an image that I want it to be medium on android medium screen and large on large screens. I know I have to put layouts in 2 different folders: medium and large layout.
But my question is, should I use one image (say the medium size) and stretch it for the alrge screen by putting min width, min hight and fitscaleXY.
OR
Should I create 2 images, one for medium sized screen and larger version for large screen?
Thanks
EDIT:
Really no answer yet to this? I am sure this is something people would do all the time. You want the image to be larger on large screens, how do I go about it? I was thinking of specifying width and hight for each screen layout size instead of wrap content.. You agree?
You dont have to make different layout xml files for each screen size, unless they really need a different layout, like how things are organised.
In Android you must specify the sizes in dp, and textsizes in sp, which is an equivalent to pixels, only they will be scaled automatically based on the screen density.
Measurement Units.
If you specify some size in dp, it may show up on a large device at for example 300 pixels, and on a smaller device 200 pixels (just an example).
I would Definatedly not hardcode the sizes per screen, since there are a lot of different screens around.
Related
In researching android image sizes for different sized screens/densities etc., I've found an absolute tonne of things, a lot of which may be deprecated, and a lot of which may not be relevant to my situation, so I thought I'd ask for general advice.
My basic question is how big should I make my background image in pixels, or inches or centimetres? Probably pixels would be best.
My app is in locked in landscape mode, I don't need to worry about orientation.
I'm using a vector image, so I don't need to worry about scaling and quality issues
So, I want my background image to fit onto a ten inch tablet, so that it fills the whole screen with no scrolling.
On phones, I want the height(which would be the width in portrait mode) to match the height of the screen, and my image will be in a horizontal scroll view, so scrolls left and right in landscape mode.
So, do I need to do the whole creating different image resources for different dpi's thing, or will one do? What size should I make it?
I will also be lining up textviews with specific parts of the image, so presumably I'll need different layouts, as the lining up of textviews relative to the image will probably vary from screen size to screen size, resolution to resolution,bigger textviews for bigger screens etc. How do I implement this?
Thanks
Vector images should be used for icons only. In your case i'd just use a drawable & make sure you have different images for the different densities. Then create different layouts for phone and tablet. You should use a scrollview on the layout for the phone
The google pixel is a good representation of an android phone: It has a 1080 x 1920 resolution at 441 dpi. Then from the the android developer docs:
xxhdpi ~ 480dpi
you can scale the 1080 x 1920 down by the (3:4:6:8:12) ratios. if you image
has a different aspect ratio make sure that that the width or the height matches with 1080 x 1920 depending on the orientation of the device
I have read Android guidelines regarding different screen sizes, but still I have some considerations.
Client has given me an image from PSD file which has certain resolution that fits
1080 X 1920. I just use wrap_content, and it perfectly fits the part
of screen.
I am not using DP to define its width-height, If i was using DP it would have
adjusted image according to screen sizes.
My questions are,
Does wrap_content works the same way as Density Pixels?
Is it also responsive, and changes the image width-height according
to different screens?
If not, then Is it necessary to use DP to support different screen
sizes ?
Thanks
The setting wrap_content tells your view to size itself to the dimensions required by its content. In the case of your test, your image is 1080x1920 and your device's screen resolution is likely 1080x1920 as well, hence the perfect fit. Since you set the width and height to wrap_content, Android is simply trying to use as much screen space as it needs to correctly display the amount of content it was supplied. In this case, since the available screen space matches the size of the content, it just fits perfectly.
But what if the device screen isn't 1080x1920? In that case, Android will only use as much space as it can, but still attempt to fit the image inside the bounds of the available screen space. In other words, the system will appropriately scale the image down to get it in the container you have provided for it. But this can lead to awkward fits if the aspect ratio isn't the same as the image. For instance, see this screenshot below:
This image is 1920x1080, but notice that it doesn't quite fit. That's because this nexus 7 screen is 1824x1200 when viewed in landscape. Additionally, the toolbar at the top of the screen is eating up available screenspace, making my viewable area even smaller and more awkwardly shaped. So while the system would love this image to extend all the way to the left and right borders, it can't, because then that would mean the height would be bigger than the viewable space. Since I used wrap_content to display this image, the system is using as much vertical space as it can, and the result is that the image doesn't quite fit the horizontal space.
So to more directly address your questions, yes wrap_content is a relative size setting that will make it easier to get a consistent look across multiple screen sizes, similar to using dp. But realize that there are hundreds, if not thousands of available Android devices on the market, and they all have varying screen sizes and densities. So your drawables may not always appear the way you want them on every device.
The way to overcome this is to supply multiple versions of your assets and provide alternate layout files for different screen sizes and densities. Once you do that, all you can do is test, test, and test some more. Use emulators for weird screen densities or devices you don't own, just to make sure you're getting the look you want. In the case of your 1920x1080 image, it looks great on that one device, but how will it fit a large tablet or a tiny handset that is smaller than the resolution of the image? These are situations you must account for in your design.
I suggest you read these resources, as they are hugely helpful in learning how to deal with issues resulting from varying screen sizes and densities:
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html
My question is just in the title.
I try to put an image to my layout, i tried this with a FrameLayout's background with wrap_content width and height and also tried with imageView with all of the possible fitScale properties.
I just cant see why my 720 px width image is HALF on the width of my phone's screen which is a samsung galaxy s3 with 720 px width....
My real question:
What is the best way to ensure that my pics in applicaion wont get any distortion?
First of all, you need to think in screen densities and dip values, not pixels. That means that you are dealing with a "virtual screen" where 1 dip (density independent pixel) represents a different amount of real screen pixels depending on the device.
For drawables you have the following categories for getting crisp results on any screen:
ldpi (Scale factor 0.75)
mdpi (Default / baseline: scale factor 1.0)
hdpi (1.5)
xhdpi (2.0)
Create different sized versions of your bitmaps based on these scale factors to get crisp results on any screen. You should start from xhdpi as highest resolution to avoid quality loss because of upscaling.
Put these different versions into their respective drawable folders (res/drawable-ldpi, res/drawable-mdpi...). These different versions of one and the same bitmap must bear the same file name of course, otherwise that won't work.
Second of all you shouldn't make strong assumptions about the device screen height and width. You need to layout your views and graphics so they dynamically make use of the whole screen not knowing the exact screen resolution. However, you can make weak assumptions about these screen resolutions based on the configuration qualifiers
small
normal
large
xlarge
Try to avoid fixed sizes for your views based on any assumptions. Always avoid "px" values in layout XML files. Use "dip" instead.
Read the documentation Supporting Multiple Screens for more information.
What you want to achieve sounds as if you want your image to take up the full width of the screen.
If you set the image as a background of any view (FrameLayout for example) then the displayed clip of the image depends on the size of that view.
If that view has layout_width / layout_height set to wrap_content then the size of it depends on the dimensions and arrangement of its child view(s).
In case of FrameLayout it depends on the size of that single child of FrameLayout.
If you're using ImageView the image will be scaled to fit into the size of the ImageView by default. The size of the ImageView depends on its layout_width / layout_height values. If you set these values to match_parent and if the ImageView has enough room "to grow" you should be able to see your image stretch all over the screen.
The "room to grow" depends on the ImageView's context in the layout. Does it have neighbors that take up room? Is the parent view too small (because of wrap_content for example)? Look for these possible problems.
I am looking at my android design for medium and large screen. I have designed my layout for mdeium screen (viewing it on the eclipse editor and emulator) and making sure it is good. My design involves textview and images view. I have create the 3 drawable folders for different density sizes so the picture can occupies the rough space on different densities.
Now, I am looking at the large screens (and even xtra large screens) but my textviews and images views looks very small (compared to the size of the screen). Therefore I would like to make use ofd the extra space by enlarging everything.
I know how to do it for text views, basically I would make textsize bigger (ie. instead of 12 sp I can make it 16sp)
But How can I do it for ImageView? The Imageview displays the image according to its size. And the size of the image is really meant for medium screen. How can I make it bigger? Should I provide the same image with a bigger size and a different name?
Please help, btw plz dont point me to the android develoment supporting mutliple screens cause I read it and I couldn't find what I need unless I missed a certain line that answers my question.
Thank you for your help
Decided to edit the question maybe people can understand my question more.
I have an image that is 50 X 50 pix in medium density medium screen size. Let say that this image occupies 5 by 5 millimeters, Now if I want to display the same image on medium desnity XLARGE screen but I want it to be bigger (say occupies 10 by 10 millimters). How do I achieve that? I understand I wil lneed different layout in the XLARGE folder so in this layout what should I do with that image view? Do I create a new PNG file with 100X100 pix and place it in the medium density folder?
you can use layout-xhdpi ,layout-hdpi etc..as per your requirement.
All of your screen xml files can be placed in multiple folders (layout, layout-large, layout-xlarge, etc.) in which you can scale the size of the UI components in DPI based upon the size of the screen. See Android documentation here.
From my understanding of the Android support for multiple screens Support, layouts are scaled for screen density and size, whereas images are scaled for screen density.
This ensures that images will appear the same size on different density screens. To overcome possible scaling issues, it is recommended to provide different versions of the images with following the 3:4:6:8 scaling ratio between the four generalized densities.
However, if I have a screen that is simply to display a photo with some text underneath, and I want to take advantage of the extra screen size in some mobiles, and therefore display the photo at a larger size from the user's point of view than on the smaller screens, then what is the best way of doing this?
Also wrt displaying images, is it best to use wrap_content or dp – what is the advantage of one over the other ?
Thanks very much in advance
P
In answer to your first question:
You probably need to specify a different drawable resource for every image you're going to do. Here is a link to the android developer's site that specifies methods of doing that. http://developer.android.com/guide/practices/screens_support.html
Second:
If you specify the dp, you may cause some image distortion, however, if you use wrap_content, it may not be big enough. I would suggest for you to use wrap_content with different drawables for each screen density.
EDIT:
To find the actual size:
Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight();
You're going to have to calculate it though based on the screen density.
And then just use mm or inches