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
Related
I set up my Android application to support different screen resolutions (ldpi, mdpi, hdpi, xhdpi, ...) and that seems to be working as it should. Different screen heights on the other hand are not scaling correctly: I optimized my design to fit on the small screens (of the default Android Studio emulators) which means that there is a lot of empty space on longer devices. Is there any way to combine screen resolutions (xhdpi, ...) with screen lenght (long, ...)? If this is not possible at all I would really appreciate alternative methods of layout scaling in order to fix my problem. I currently use dp and RelativeLayouts only.
Thanks in advance.
RL in the picture below represents RelativeLayouts.
I would suggest using multiple nested linear layouts while specifying layout weights to scale components on all kinds of displays (see this guide for example). Tip: You can use empty views to create dynamic spaces.
Also in some cases it is useful to specify portrait and landscape layouts separately (see this guide) although then you have to manage some duplicate code.
I'm in the process of creating a small questionnaire. Although all views are constrained, the individual text views overlap or slide to the edge.
So far I have only created the design for the layout and have not yet linked any functions with anything. When I display the layout on a larger display, everything is shown as it should be.
Can someone help me and tell me how I can design my layout so that it automatically adjusts to the display size?
I'm really new about programming in Android and don't know all the backgrounds I may have disregarded.
I tried to use the AutoSizeMaxText fuction but I'm not sure if I used it the right way.
As far as I know there is no such thing as an automatic function to support different screen sizes.
What you can do:
Use constraintLayout
Use match_parent and wrap_content instead of hard-coded sizes in your xml
Create different layouts for almost every (if not every) screen resolution:
ldpi, mdpi, hdpi, xhdpi, xxhdpi
Use stretchable nine-patch bitmaps for image resources.
Consider using fragments and double-pane structure for large devices
You may want to chek this library: https://github.com/intuit/sdp
and this one for text size: https://github.com/intuit/ssp
Don't forget to test it in as many devices with different resolutions and pixel density as you can.
You can check the official documentation for this issue: Android developers: Support different screen sizes
I am working on a app in which there are some textfiels and button when I am running it on different screen size devices it is showing unexpected result as shown in the below image!
[Image 1] http://oi45.tinypic.com/25yvon4.jpg
[Image 2] http://oi45.tinypic.com/xmlqns.jpg
Here in first image some space is left vacant at the bottom due to large screen size and in second image the last row of buttons are hidden due to small screen size.Also for buttons I am using Table Layout.
Is there any way to solve this problem.
That's a broad topic that needs spatial understanding first.
Here's a good place to start - http://developer.android.com/guide/practices/screens_support.html
Long story short, always use point units (dps), try to avoid to hardcoded pixels within your code, position items in a relative way (ie.: in relation to other object - RelativeLayout, LinearLayout, etc) and make sure to take advantage of the power of "values-..." folders.
Example
values-xhdpi (XH)
values-hdpi (H)
values-mdpi (M)
values-land (Landscape)
values-sw600dp (smallest width at least 600dp)
....
Use layout, layout-large and layout-xlarge resource folders to customize your layout files if you care about various screen sizes. Test these layouts on phones, 7" and 10" tablets to cover all of your bases.
For small phones of less than 4" screens (qvga) as well as older devices (wvga), make custom layout files (in the layout folder) and refer to them dynamically in your java code when you detect these kinds of devices. Again, test on these older & smaller phones as much as possible. Borrow some phones from the Sony Device Loaner Program in order to get real-world testing done.
Lastly, use ScrollView to embed your layouts if you want vertical scrolling on smaller screens. Don't go crazy trying to fit everything on a smaller screen. Sometimes scrolling is a natural solution that your users will understand.
You must have to make screen for all devices if you want to solve your problem.Read below document for different screen:-
http://developer.android.com/guide/practices/screens_support.html
or
You can use weight or layout weight to prevent this problem.
Getting my head around Android, I've sort of trouble understanding support for multiple
devices. I've gone through the dev-docu, now for the clear-up:
The idea behind using dp is, that e.g. a button has the same 'real-world'-size, independent of the actual screen-size, right?
If so, that means, I provide the images in ldpi, hdpi and so on. That results in a button, that has always the same size.
If still correct, I understand that now, that my buttons always has the same size, I should provide different layouts, because on a small device, there might only be space for two next to one another, where on a larger device there's room for three.
If all of the above is correct, my question would be, how I deal graphics-tool-wise with it. Say I have a button 100px x 100px at 300dpi, what sizes and dpi's would that be for the new documents in e.g. Gimp for the different screensizes?
Thanx in advance for any smoke-lifting!
Marcus
What it means when you can use your custom assets for different screen densities is that when you put those respective assets, they will not scale again and use them as they are. Now it is true that the size of the screen also varies. That is when you can consider tweaking your layout.
For example in a large screen you may be able to fit two components beside each other and use a linear layout with horizontal alignment. But when it comes to a small screen, that might not be possible and one option is to define a new layout for small screens and say pt those two components in a vertical layout.
For more information regarding how to implement this and best practices, check these Android Docs
After some more study, it seems that the graphocs-tools DPI are actually the one referred to in e.g. the baseline. So to create a baseline-doc, you indeed create a document 470 x 320 pixel in size and a resolution of 160 dpi. The rest goes from there.
My layout as shown below looks very different depending on what screen size it is projected on to. I'm aware I can improve this somewhat using different layouts for each screen size but considering I have followed the best practises described in the android multiple screen support documentation (using dps, no absolute layouts etc) I wasn't expecting the results to look this bad so I fear there is a further underlying problem.
Code:
http://pastebin.com/D96ue9sc
Your layout is fine and completely as I would expect it. You shouldn't mix up density independent pixels with fully dynamically layouts.
DP just means that the value is calculated according the density types. The density itself has nothing to do with screen resolutions. 60dp are 60px on a mdpi device, it doesn't matter if the screen is full HD or just 480x360. But the result is, of course, very different because the calculated 60px are nothing on a HD screen but a lot on a small one.
You have not other possibility but to provide different layouts according to the screen size/resolution.