Android layout screen resolution problems - android

I have almost finished my app for android, the problem is when i test it on multiple screen sizes the layout of items such as padding etc, seems to be incorrect. I don't understand how I am supposed to support all screen sizes, because I have used all 'dp' values for the text and sizes for padding etc. I am using the 'background' as an image which fills the screen, and the background includes the layout of buttons and boxes that will have textviews overlaying them. I have been testing on my HTC desire and I have just noticed this issue. I assumed that it would all be okay seeing as I have been using dp for all measurments etc. Any tips to fix my layouts would be appreciated as my app is pretty much good to go apart from this :(

Read the following links very carefully you will get the best way to do:
Supporting Multiple Screens
Support for Multiple Screen Resolutions
Support for additional screen resolutions and densities in Android
compatible-screens
MultiResolution - Multiple Resolutions

Related

How to add screen layouts for different screen sizes in android? (Update 2020)

I tested my application for screen sizes for 6 inches - 6.5 inches(on a one plus 6t/7t) and above and it's scaling the UI elements properly for it. But when I tested the application for screen sizes of 5 - 5.5inches, it's going out of the constraints and off the screen.
These are the things that I have tried:
Having wrap_content and match_parent with most of the UI elements(Textviews, Buttons to name a few)
Using constraint_layout which is the default layout in Android Studio 3.0 with all the constraints set for every element
I also tried understanding this document but I could not clearly understand this
Lastly, I came across their solution of having a different screen layout for different screen size. For this, what would I have to do? Create a new Layout and copy my Design XML text in the newly created layout and adjust scaling accordingly or is there a better approach for doing so?
Also, any other suggestions or any other approach to solve this would also help.
Edit 1:
So I figured something out, The UI is not setting correctly for xxhdpi resolutions. To compare, two screen sizes of similar sizes (1080x1920) having 420dpi and xxhdpi resolutions, the former works correctly but the latter does not. Any clues on how can I create or deal with xxhdpi resolutions?
[try with this,you can update AS]
[1]: https://i.stack.imgur.com/oLqHI.png

Combining screen height with different resolution layout files?

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.

Is there a function in Android Studio to automatically adjust the layout to the display size?

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

Android - common techniques for scaling screen layouts

I realise this topic has been covered to death, and I have read the official and unofficial developer guides on it so know the theory. But I'm still unsure which path to take to ensure my app looks good on multiple screen sizes. My app is a simple navigation style app which is designed to be portrait only. At this stage I'm not interested in making different designs for landscape or multi-pane screens for tablets etc. I just want each screen to be scaled up/down so it looks in proportion with the screen size it is being displayed on - i.e. text and images are sized up/down as appropriate. I designed the app for a classic 480x800 hdpi device which it looks great on, I just want to make it look in proportion for the Galaxy S3/Nexus 7 etc. I'm already following these guidelines :
Using RelativeLayouts
Using DP units for padding/margins
Using SP units for fonts
Using 9-patch images for buttons
However I'm finding it still looks small and a bit lost in the middle of the screen on the larger devices. In particular, my main menu screen is a grid of 6 image buttons which I can't get to scale well. I don't want to have multiple copies to maintain of the same screen (normal/large/xlarge), just want one layout. I was considering the following :
Using value-normal/value-large etc. folders to store XML files with DP/SP values for sizes of images/text
Changing RelativeLayouts to LinearLayouts with weights (although I initially struggled with LinearLayouts and changed to RelativeLayouts
Are either of these valid approaches, or is there a better approach?
Personally, I would go with the first option. While this will work well for phones, it will make the layout seem somewhat bloated on tablets. Hence, another approach would be to create separate layouts for tablets and place them in the layout-large and layout-xlarge folders for 7" and 10" tablets respectively.

Android: support multiple screens

I am trying to make a application in Android. I want that it should be able to run on multiple phones of different screen sizes, so i studied support multiple screen on developers and according to that i have to create 3 different xml files for supporting three different screen sizes and also 3 different types of images for each type of xml file. But on a blog i get the idea of doing this by using current screen size method. So i am confused what i should do. means which is optimized and performance increasing way. And which one will be more perfect for supporting all types of screen(except extra large screens)
Defining height, width and other parameters in the XML file is the better option rather than on run time.
Because XML files works as metadata (data carrier) to the activity and avoids alot of confusion when onCreate mothode in called.
Plus, create different folders for image quality (hdpi,xhdpi,ndpi,ldpi)
7 inch device use mhpi
10 inch devices use hdpi and xhdpi
While NEXUS tabs use hdpi and xhdpi irrespective of their size.
Mobiles use ldpi and ndpi.
Beauty lies here is that android device automatically pick-p the suitable content when found, i.e layout and image.
If not found it would first search other Layout folders,e.g a layout not found in x-large folder then it will search in large,then medium, small, which one of them suits the best ,(if a layout is not found in its respective folder).
Nexus will create alot of trouble for you.
To check how your layout would look on different devices, try using the options, which tells you how it would look on that device with those height width, present in the Graphical (view of a ) layout.
You can use three different layouts for different screen sizes ,and android will pick the suitable layout , but Using three different layouts for each type of screen format will not be a good idea , because it will cause problem in handling all layout , if screens are less then its fine but if number of screen increases it will get difficult . Like if you forget to add change in one of the screen size it shall crash with any exception .
What you can do is keep images of different size in different folders and practice layout to make standard in one layout by using layout weights , and margins in in dp .
See my this answer
Table Layout spacing issues
and check this layout will look similar for all screen sizes.
If your design is same for all screens sizes you can use dp and have only one xml for all screens.
But you should support icons for all screens.
I think it's less confusing David Ohanyan way, but forgot to say something...
Whenever you can, use styles in your xx_layout, images, etc, so you'll have 1 layout.xml and 3 styles files inside folders: values, values-small, layout-large.
At least for me, it's less confusing than opening 30 different layout files.

Categories

Resources