android multiple screens compatibility - android

I read info about "Supporting Multiple Screens" and other post here... but Im really confused about how can I develop my application that run on multipple devices.
I was starting develop on a determinate screen (normal size layout), then I run my apk on a S4 galaxy so I see that every object of my apk was diferent size to my xperia to the S4.
what I need to do to make my apk compatibility for all the devices?
I read information that the only source to make that is:
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
For:
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
is this true? so I need to make different layouts for different devices?
guys please help me with this issue cz I relly dont understand how is the deal for multiple devices compatibility.

For the layouts:
You can most likely get away with one set of layouts for your application. By default, Android's gui system is done in such a way that you should be able to make good use of the screen of any device, for example use layout_weight and specify things in dp (density-independent pixels). By providing only one layout though, you're most likely going to have it optimized for phone or tablet sized screens. If you create it for phones, then tablets will probably have a lot of empty space, whereas creating another set of layouts would allow you to put extra info on the screen than the phone layouts could fit. It depends how willing you are to customize your app experience for each users device. To create multiple layout, it's recommended to use the Android 3.2 size qualifiers. For tablets, you could use res/layout-sw600dp. See here under "Using new size qualifiers".
For the drawables:
You will most likely not want to have just one set of drawables. You can, and the Android system will scale all your drawables to maintain the same physical size on all screen sizes, but due to scaling, the images will not look very good. That's why you provide an image that will look good for each "category" of screen density, and the Android system will choose the one for that device's screen density, and any scaling it has to do will be minimal.
It is kind of confusing at first, but you most likely don't have to worry about the layouts specifiers just yet. I would make sure to read the supporting multiple screens article and writing your xml layouts such that they make use of the screen size in a relative way.

Have you read this page? Or this one?
You create resources with duplicate names located in folders that are qualified a certain way. At runtime, the system will choose the resources that best match the current configuration of the device. If you want your device to work on multiple screen sizes and multiple screen densities, you will need to create different resources (layouts, drawables, etc) and qualify them appropriately.

Related

When scaling is determined, why is there a need for both screen size and density?

When scaling (A layout, an image, and so on), Android determines the scaling based on two factors: Screen size and screen density.
Why is there a need for both of them?
For simplicity, let's assume an app that has a single layout file, with several elements defined with dp units, and with no provided alternative resources.
In such a case, a scaling is applied (listing 2, Italic added):
At runtime, the system ensures the best possible display on the
current screen with the following procedure for any given resource:
The system uses the appropriate alternative resource [...]
If no matching resource is available, the system uses the default
resource and scales it up or down as needed to match the current
screen size and density
Now, given the above, what would not be possible, scaling-wise, if scaling would have been determined only by one of these factors?
A side note:
Numerous resources online regards the scaling functionality, but I'm having a hard time finding a direct explanation for the need of Android to use both size and density factors for it.
To add on that, the most cited resource, Supporting Multiple Screens, left things unclear for me when first stating that the four generalized sizes (small, medium, large, xlarge) are deprecated beginning with Android 3.2, while later repeatedly referring to those generalizations as if they are still used (E.g., when stating that "the system uses the appropriate resources based on the generalized size or density"), and other documentation pages do so as well (E.g., the table here).
On the other hand, the above cited page defines only one type of independency - a density independency, and not a size independency. Therefore, I was left confused.
the system uses the default resource and scales it up or down as needed to match the current screen size and density
I think this is written in a confusing way, but is generally true. Image resources are scaled based on the screen density (when an appropriate alternative resource is not specified), but other resources can be "scaled" based on the screen size. For example, a layout resource will be "scaled up" on a tablet as opposed to a phone. I don't really know why the documentors chose to call this "scaling", but I believe this is what they mean.
In other words, the resources framework provides qualifiers for both density (e.g. -xxhdpi) and for size (e.g. -xlarge or -sw720dp), but will use non-qualified resources as fallbacks.
the four generalized sizes (small, medium, large, xlarge) are deprecated beginning with Android 3.2, while later repeatedly referring to those generalizations as if they are still used
They are deprecated, and yet they are still used. You are free to go ahead and create a layout-xlarge directory and put alternative layouts in it, and the system will use them when it deems doing so appropriate. It's just not recommended; you're better off using the -swXXXdp qualifiers these days, as this gives you much more control over your layouts.
You usually need bigger margins or layout with different positions (like side by side instead of vertical) with the same views in bigger screens (small, large, xlarge, etc).
But for densitities (mdpi, hdpi, xhdpi, etc) usually you just need bigger image resources (bigger with the original resolution and thickness) so you dont rely on the default scale up image algorithm of Android for images (leading to blur images).

android is it standard to make buttons text and other views text larger in tablet size?

Is it standard to make buttons text and other views text larger in tablet size? I make dimens.xml for different device sizes and make different text sizes for different device sizes. for examle in normal dimens file:
<dimen name="small_text_mobile">14dp</dimen>
and for large size dimens file:
<dimen name="small_text_mobile">18dp</dimen>
and use this dimens for my textViews and buttons , extra..I want to know if it is standard? or no need for that and texts of views like buttons should be in same size in different device sizes?
The unit used (dp) will convert the button and layout sizes to appropriate pixel sizes on the actual device (making them independent of actual device screen size). Therefore, on a small device it will look relatively similar to a large device. However, depending on the situation, it may be more efficient use of screen space to have different dimensions/layouts for different screen sizes. It really depends on the view being used and the level of user experience required for it. A lot of the time dp will get the job done close to what you would want. The Android documentation on supporting multiple screen sizes is excellent in explaining all the different situations and control a developer could have on their layouts.
Depending on the layout, it may be better practice to create multiple layouts to fit small and large screens in different orientations. It depends on the layout and how complex it is. If it looks unnatural on a certain device, I would recommend creating another layout (or applying some changes on the current one) to better fit all devices.

Android layouts size and resize

I am doing a lot of work about android layout I still can't create a layout working in every phone. I am not sure about best the way to create a layout so correct me if I am wrong . There are three things to keep in mind :
Screen px (resolution, for example 1080x1920 px)
Screen dimension "inches"
Screen density dp or also called dpi ( dp is a virtual resolution, it's correct?)
To draw a layout working in every phone (my app will works for phones) do I have to create a directory "layout-kindofdensitydpi for every screen density (layout-ldpi,layout-mdpi,layout-hdpi,layout-xhdpi,layout-xxhdpi,layout-xxxhdpi) and draw "manually" or do I have to do something else?
I did a test, I created these 6 directory and drew manually for every resolution. It requires a lot of time, also device with a resolution of 768x1280 my app doesn't respect what I drew, for example spaces aren't respected, the collocation of elements doesn't result correct and frame layout with ImageView inside isn't scaled.
What I have to do? In some Android books isn't mentioned that elements could not resize and usually them explain how to put some text or image without analyse resize in every device.
Thanks in advice
First you should find the appropriate layout type for your UI (RelativeLayout or LinearLayout). Sometimes using a good layout(or nested layouts) can make the UI look good on every screen. I prefer LinearLayout cuz I can simply set layout_weight for components.
Then set different sizes in dimens.xml file for different densities or screen size buckets. Like this:
And you can also use match_parent or wrap_content
Don't forget to set the screen orientation of your activity if it doesn't need to rotate. Having one orientation makes it much easier to design.
If you couldn't make a good layout using tips above you should create multiple layouts to fit every screen size or density (Screen size and density are two different things).
You should find the best way to determine your screens according to.
Screen size bucket (small, normal, large, and xlarge) picks a layout that fits the screen (or the closest), density bucket (ldpi, mdpi, hdpi, xhdpi, xxhdpi, and xxxhdpi) picks a layout according to the density ,or the smallest width (I think it's almost the same thing as density).
480dp is the sw of these two devices
You can make layouts for different screen orientations too.
I don't like creating layouts for different screens for some reason. One of them and the most important is that sometimes same screen sizes have different densities and it makes it hard and time consuming. To create a layout and you should also provide a lot of pictures.
Use
android:layout_width="match_parent"
android:layout_height="match_parent"
to the outer layout to get access of the full screen of the device.
Also, if there are no changes in your UI then you don't need to create different layout folders.
Refer http://developer.android.com/training/multiscreen/screensizes.html
You should have a look at
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/training/multiscreen/screensizes.html
http://developer.android.com/training/multiscreen/index.html
I would suggest using layout-swXXXdp or layout-large etc instead of layout-KindOfDensitydpi
Create your relative layouts using RelativeLayout and use the weights of LinearLayout. Don't hard code any of the positions in the layout

Is it necessary to create "small, normal, large and xlarge android xml layouts" folders if i want my application to run of all Android devices

I am developing an Android Application that supports all kind of Android devices like mobiles and tablets. But it's time consuming to create multiple folders (small, normal, large and xlarge android xml layouts) to support all the Android devices. Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc?
You only need to create unique layouts (ie. *layout_mdpi* ) if you want something unique for that particular screen size.
If you want to use the same layout on all different screen sizes, you will only need to create a single layout (in the layout folder).
Only if you want to customize a particular layout would you need a new FOLDER in layouts (named: layout_mdpi) in that folder you would have multiple copies of customized layout with same name (ex. my_layout.xml)
To clearly answer your question - you will only need the layout folder and no other ones in your casel
Ex.
res\layout\my_layout.xml // this folder is all you need if this layout will work on all screen sizes
res\layout_mdpi\my_layout.xml // you ONLY need this if you are presenting something unique on this screen size.
In Android we need to maintain different folders for the layouts with different resolution reason behind it is the use or the resolution of the Android Device on which the application gonna execute.
small Resources for small size screens.
normal Resources for normal size screens. (This is the baseline size.)
large Resources for large size screens.
xlarge Resources for extra large size screens.
Android OS select the specific layout it self by checking the compatible device and its resolution.
So, better to create folders to support in multiple screens
For More Info refer this
Is there any way to build an android app that runs on all android devices without creating these folders:small, normal, large, xlarge etc
Consider this, you have a button (with match_parent) that stretches full width of a screen in portrait mode of a 4 inch phone, that's fine it looks alright, but then that same layout on a 10 inch tablet in portrait is now 3-4inch wide, that's not great looking.
"So what" you say, make it wrap content, okay then so the button now only fills up part of the width on phone, still looks okay but then on a tablet you have huge amount of space now either side of the button, maybe that's looks okay, maybe not.
Maybe same button on a smaller screen takes up too much space?
Now apply the above to every single layout element in your app.
Do you think it'll look good, using the same layout, do you think your users will be okay with an app that was so little care to its UI and UX?
SO, in conclusion, yeah it's possible to only use one eg normal, for all devices but it'll probably look terrible on most of them.

Android support screen design

I know about supporting multiple screens in Android and I use it in my app. But supporting different screen sizes and DPI makes your application size large. We all know about the 50mb file size limit in Google Play right? So, is it possible to create a folder like the following?
\layout-small-160
\layout-normal-240
If that is not possible do any one here knows how to support multiple screen sizes and its DPI's without using too much image to make my application size smaller?
I only give my suggestion and you can try it.
By default, we have three drawable folder drawable-ldpi(120), drawable-mdpi(160), drawable-hdpi(240).
When the App need image, Android will find the image according to the screen destiny. Obviously, the image in drawable-ldpi folder is fit if the app running on phone which have a low destiny.
But if there is no image in drawable-ldpi folder. Android will find if there is image in drawable-hdpi. If it exists, android will scale the image(0.5) and show it.
So you don't need to prepare images for every destiny. You only need to prepare the image for hdpi scrren. And for some individual images which demand accurate size, you need to prepare for the three destiny.
You could download some famous APK and extract them.Then enter the res folder to check how the author did.
Sorry for my poor English.
From Supporting Multiple Screens article of Android documentation:
To optimize your application's UI for the different screen sizes and densities, you can provide alternative resources for any of the generalized sizes and densities. Typically, you should provide alternative layouts for some of the different screen sizes and alternative bitmap images for different screen densities. At runtime, the system uses the appropriate resources for your application, based on the generalized size or density of the current device screen.
Therefore, yes it is possible to create folders for different layouts as you mentioned in your question. The following is a good practice of having your resources folder organized for different screen sizes and different bitmap drawables:
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
Yet, you do not need to provide alternative resources for every combination of screen size and density. The system provides robust compatibility features that can handle most of the work of rendering your application on any device screen, if you develop your application following the instructions described here.
2 suggestions:
Resize the images to be exactly the size you need. Use proper compression (use a professional application to edit the images, like photoshop, that optimize the image and compress it well).
Put part of the images on an external server and download all on the first use. Downloading the images from the server has the advantage that you know the device size, so you can download only the relevant sizes.
Case close.. It is posible to create a folder that has two modifier..
like this
layout-normal-hdpi ---- this will only set the view from specific phone that has 240 dpi and normal screen
thanks for all who commented and give an idea here..

Categories

Resources