how to make designs compatible for all devices [duplicate] - android

I understand there is plenty of documentation about designing for multiple screen support in Android. and I have read the Android guide here as well as a number of similar questions such as this
However I'm still a little confused as to how I should implement it for my application. I plan to target the following device configurations
Am I correct in thinking I will need to structure the project layouts as follows:
Medium density Normal screens HVGA 320x480 (160dpi):
res/layout-mdpi (320 x 480 )
res/layout-land-mdpi (480 x 320 )
High density Normal screens WVGA800 480x800 (x854) (240 dpi)
res/layout-hdpi (480 x 800)
res/layout-land-hdpi (800 x 480)
But what about the Medium density, large screen devices?
I plan to use sets of both high and medium density drawables too. My primary concern at this early stage is using suitable background images for each layout. For example, to support both the 480x800 and 480x854 sizes, I plan to simply use an ImageView as the background such as:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bg"
android:scaleType="center"/>
The 'bg' drawable will always be 480x854 and by using:
android:scaleType="center"
I'm hoping this will take care of those two screen sizes. Whereby the image keeps its original appearance but is centred on the 480x800 screens. I will lose some pixels off the image but as long as the image isn't scaled then that suits my needs.
I plan to have a set of 320x480 assets for the normal screens.
I'm just hoping I'm following the correct procedure here so I appreciate any info/tips from you guys. Thanks in advance

In my experience you don't really need to customize your layout for the small/medium/large/etc screens, as long as you have your drawables for the different densities. Like the documentation says, Android will attempt to render your layout properly on different screen sizes.
By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes.
The 'other cases' applies only if you really want to change your layout on larger screens.
Using android:scaleType="center" works for me, but it will, like you said, leave empty space around your layout on larger screens if it should fit on smaller screens as well. If you have a fully customized view with 'widgets' that should be placed exactly right, and you don't want to be programmatically determining the scaling and applying the same scaling to your widgets, this is definitely the way to go.

Related

multiple screen support issues [duplicate]

I understand there is plenty of documentation about designing for multiple screen support in Android. and I have read the Android guide here as well as a number of similar questions such as this
However I'm still a little confused as to how I should implement it for my application. I plan to target the following device configurations
Am I correct in thinking I will need to structure the project layouts as follows:
Medium density Normal screens HVGA 320x480 (160dpi):
res/layout-mdpi (320 x 480 )
res/layout-land-mdpi (480 x 320 )
High density Normal screens WVGA800 480x800 (x854) (240 dpi)
res/layout-hdpi (480 x 800)
res/layout-land-hdpi (800 x 480)
But what about the Medium density, large screen devices?
I plan to use sets of both high and medium density drawables too. My primary concern at this early stage is using suitable background images for each layout. For example, to support both the 480x800 and 480x854 sizes, I plan to simply use an ImageView as the background such as:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/bg"
android:scaleType="center"/>
The 'bg' drawable will always be 480x854 and by using:
android:scaleType="center"
I'm hoping this will take care of those two screen sizes. Whereby the image keeps its original appearance but is centred on the 480x800 screens. I will lose some pixels off the image but as long as the image isn't scaled then that suits my needs.
I plan to have a set of 320x480 assets for the normal screens.
I'm just hoping I'm following the correct procedure here so I appreciate any info/tips from you guys. Thanks in advance
In my experience you don't really need to customize your layout for the small/medium/large/etc screens, as long as you have your drawables for the different densities. Like the documentation says, Android will attempt to render your layout properly on different screen sizes.
By default, Android resizes your application layout to fit the current device screen. In most cases, this works fine. In other cases, your UI might not look as good and might need adjustments for different screen sizes.
The 'other cases' applies only if you really want to change your layout on larger screens.
Using android:scaleType="center" works for me, but it will, like you said, leave empty space around your layout on larger screens if it should fit on smaller screens as well. If you have a fully customized view with 'widgets' that should be placed exactly right, and you don't want to be programmatically determining the scaling and applying the same scaling to your widgets, this is definitely the way to go.

Screen sizes of android

I am creating some background images that will cover the "entire" screen of the phone/tablet screen for my app. These images are for the Splash Screen. Basically, my application must support to Phones and Tablets.
I created a huge image which is 2560 x 1600, now time to resize it. But the case is, I am stuck here. What are the screen sizes for mdpi, hdpi, xhdpi, xxhdpi ? These are the screen sizes from phone to tablet right? I need these sizes in pixel values.
I have already visited to the android developer links like supporting multiple screens, but I did not find anything good from them.
Please help me to resize my images by providing the correct screen values in pixels.
Hdpi, xhdpi, etc. are not screen sizes, they are screen pixel densities. If you want to adjust your image according to screen sizes, you should use small/medium/large/xlarge. (And combine it with hdpi/xhdpi/... for sharp and accurate results :))
You can always use some most common resolutions, like HD, fullHD, 800x480 etc. But you have a bigger problem - differences in aspect ratio. Newer devices tend to use 16:9 aspect ratio, but older models with 800x480 screens are different, so you should consider some padding/cropping to ensure image is not stretched, and just then worry about resolution.
Good luck with that :)
Edit:
You can create your own resource folders, you can even use multiple modifiers.
http://developer.android.com/guide/topics/resources/localization.html
Just create folder 'drawable-small-hdpi' or whatever and it will work :)
You can also use other modifiers, f.e. drawable-de-small should load specified drawables only on "german speaking" devices with small displays.
About image sizes: documentation(the article you are linking) states:
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
So you if you want good compatibility, you go like this(in pixels):
small-mdpi = 426x320
small-hdpi = 639x480
small-xhdpi = 852x640
normal-mdpi = 470x320
normal-hdpi = ....
......
xlarge-hpdi = ....
xlarge-xhdpi = 1920x1440
Just remember that 1 dp in mdpi is 1px, in hdpi it is 1.5px, xhdpi is 2px and xxhdpi is 3px.
In practice, you really don't see many xxhdpi devices with small or even normal screen, so you can omit some extremes. If you don't care about some stretching here and there on smaller phones, you can even completely ommit the small option and rely on the match_parent attribute to fit the image.
But you still have to design carefully because these are just minimum sizes.
Also consider phones with hardware buttons and software buttons - with hardware buttons and same screen, you get more space for your app, so, again, different aspect ratio!
From my experience, I would recommend splitting your splash screen in elements that must at all times remail "good looking", like logo. And then define some background that can stretch a bit here and there. So that you can set the background to match_parent and always cover whole screen and "logos" to wrap_content or fixed size in dp so their aspect ratio won't change and pixel size can be easily calculated.

android image size from web

I'm trying to support mdpi, hdpi and xhdpi on my current App. The problem is that I'm fetching images from the web (profile pics). I'm using an imageview with height = 200dp the thing is that even tho I have read tons of tutorials and documentation about dp and dpi, I still don't get them.
So my problem is that on an hdpi phone (atrix 2) the image takes about 1/3 of the screen, which is perfect for me. but on mdpi (galaxy ace) it takes almost 2/3.
What's the best way to set a height for an imageview (from the web, not resources) to support mdpi and hdpi.
thanks
<ImageView
android:id="#+id/expositor_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#+id/expositor_info_header"
android:layout_centerHorizontal="true"
android:layout_marginTop="-27dp"
android:contentDescription="#string/misc_placeholder"
android:scaleType="centerCrop" />
basically my problem is that the 200dp takes different % of screen on mdpi and hdpi
For starters, you are going to want to set a scaleType (try "center_inside") in your xml definition of the ImageView.
If you provide some code (in particular your layout xml file) I might be able to be of more assistance.
Update
Now, this may not fully be your problem, but it is a piece of it. DP (or DPI, they are the same thing) adjust for the screen density (pixels per inch), not the screen size. That means that an image of 200dp x 200dp will be approximately the same size in inches on both screens, not the same percentage of the screen.
Specs:
Atrix 960 × 540 (https://en.wikipedia.org/wiki/Motorola_Atrix_2#Features)
Galaxy Ace 480 x 320 (https://en.wikipedia.org/wiki/Samsung_Galaxy_Ace)
Since the Atrix is hdpi, and hdpi is a 1.5 multiplier, 200dp will take up 300px in real pixels, or approximately 1/3 (300/960) of the screen as you point out.
On the mdpi Ace, the 200dp translates evenly to 200px, which should be closer to 1/2 the screen. However, with the addition of the actionbar taking up screen real estate, it may seem like more.
The best way to deal with very small screens like the ace... well, my normal solution is to not support them very well, at least not on my first pass, as they are pretty rare. But if you want to, the best way is to provide alternate layouts.
For Example:
Create a folder named layout-large (or similar, see: http://developer.android.com/guide/topics/resources/providing-resources.html#Compatibility).
Make a copy of your existing xml file in that folder. (name must be exactly the same)
Modify the file in layout/ so that it works better on smaller screens.
Essentially, if the device has a "large" screen or above (where large is basically the standard these days), it will use the layout in the layout-large/ folder.
Otherwise, it will use the default layout in the layout/ folder.
If you think this explanation is not what is happening, please provide screen shots to verify that the layout is in fact not behaving like it should.

Is it correct way to create separate layout file for supporting different screens? [duplicate]

I'm really feeling confused. From the docs at developer.android.com, it seems in order to keep my images scaled correctly (aspect ratio too) across all current Android devices I need all these layouts below. Is that really what everyone is doing? Am I missing something, or should I be going about this a different way?
Low density Small screens QVGA 240x320
------------------------------------------------
layout-small-ldpi
layout-small-land-ldpi
Low density Normal screens WVGA400 240x400 (x432)
------------------------------------------------
layout-ldpi
layout-land-ldpi
Medium density Normal screens HVGA 320x480
------------------------------------------------
layout-mdpi
layout-land-mdpi
Medium density Large screens HVGA 320x480
------------------------------------------------
layout-large-mdpi
layout-large-land-mdpi
High density Normal screens WVGA800 480x800 (x854)
------------------------------------------------
layout-hdpi
layout-land-hdpi
Xoom (medium density large but 1280x800 res)
------------------------------------------------
layout-xlarge
layout-xlarge-land
Your app will work on 100% of the devices with the classic layout.
You can just add some buttons or change the layout in landscape mode by adding some qualifiers but that's up to you!
For instance, on LDPI (small resolution) device, you may want to adjust some buttons or change a little bit to fit the small screen.
You may also want to put some buttons on the right in landscape mode and in the bottom of your layout in portrait!
You do not "have to" use them.
According to Android Dev Protip from Roman Nurik about screen size qualifiers:
If you have custom layouts for larger screen devices such as tablets,
now's the time to stop using the -large or -xlarge resource qualifier
and switch to using -swXXdp or -wXXdp qualifiers. The latter were
introduced in API level 13, which basically all tablets now have
support for according to the latest platform version charts1.
means that for basically all cases where -large would have any effect,
-swXXdp can be used instead to provide more granularity.
So which actual sw or w qualifiers should you use? Here's a quick
just-give-me-something starting point:
7" tablets: Instead of layout-large, use layout-sw600dp.
Example: Nexus 7 = 960×600 dp; the smaller of the two dimensions is
600.
10" tablets: Instead of layout-xlarge, use layout-sw720dp.
Example: Nexus 10 = 1280×800 dp; the smaller of the two dimensions is
800. Some 10" tablets are a bit more narrow so 720 is a commonly used switching point.
There's more to it than just that (you really want to choose switching
points based on your content's minimum requirements, not on device
form factor), but that's a #Protip for another day (::cough:: +Nick
Butcher ::cough::).
In the layout if you do not use AbsoluteLayout, you application is going to be resized to fit the screen.
But in some cases, for smaller screens you need declare a new layout with less components for example.
For images:
You has some options.
Simple ignore some resolutions and let the device choose the best image to it.
Declare on AndroidManifest for wich sizes you want to support.
Or has just one and let the resize screw your application.
Yes. You should define different layout for different screen resolution.
When you are supposed to work with tablet kind of application. That time really you feel that. There is a need of different layout. Because Tablets always comes in different size.
One more thing, When you are working on android, means you should always taste your app with real device. And also test with different size emulators.

Do I need to design background for each device size?

Dear All I’m going to work in android application I should design the interface. I read articles on http://developer.android.com/design/index.html but I still have some missing point.
Do I need to design back ground for each device size ?
Check for this Link for supporting multiple screen. This link will show you how to create the different layout for different screen size devices.
But even if you want to make a Unique layout for supporting multiple screen in orientation or portrait mode then,
For image, use 9 patch images.
Here is the link http://developer.android.com/tools/help/draw9patch.html
For width and height of any widgets, use wrap_content or match_parent or you can use android:layout_weight and android:weightSum
Avoid using the pixels i.e. px
Use dp
By this you can create the unique layout working for multiple screens, but that screen should be in orientation or portrait mode.
If you want to support for for both,then you have to createlayout-landfor landscape mode in the res folder.
Actually, you should. There are 4 main screen sizes in android those get layout xmls from res/layout-xlarge, res/layout-large, res/layout-normal and res/layout-small. At the same time, you should use different image resolutions for different screens those get images from drawable-hdpi, drawable-xhdpi, drawable-mdpi and drawable-ldpi.
It depends on the background type. If your background is an image with high resolution you should provide different images for different screen sizes if the whole background is an image.
You can also:
Make background from tiles (like icloud.com)
Specify a ninepatch image if your image is something like a frame where corners should remain the same and the body should be scaled (not very good if you have some picture)
Specify multiple different images for different screen resolutions and densities. To do so read supporting multiple screens. If you need even more precision in image scaling and quality you can use the fundamental size of screen attribute which is sw<N>dp - you can specify the smallest width of the screen where your image should be used. This is a qualifier name for a resource folder.
Some values you might use here for common screen sizes:
320, for devices with screen configurations such as:
240x320 ldpi (QVGA handset)
320x480 mdpi (handset)
480x800 hdpi (high density handset)
480, for screens such as 480x800 mdpi (tablet/handset).
600, for screens such as 600x1024 mdpi (7" tablet).
720, for screens such as 720x1280 mdpi (10" tablet).
You should also have a look at other qualifiers that make Android choosing image at runtime (screen density, Available width, Available height, Screen size or Screen aspect). By combining these qualifiers and testing carefully you will be sure that the user has the best experience on each device.

Categories

Resources