Different WIDGET margins on different phones with android 4.0-4.2? - android

I've small problem - I've and app (home screen widget) for android ICS and higher. But different phones with different OS version (4.0.4, 4.1.2, 4.2, etc) and also different brands (Samsung, HTC, LG, ...) makes my app look diferent.
Ok, it doesn't happens always, but on some phones just Android adds automatic margins to my own - and on some not!!! How is this possible, and how to avoid this? Looks like every brand does it in their own way - which is fine for them, but bad for me :)
EDIT:
I use dp, not px. The main problem is not in dp/px nor in portrait/landscape changes. Main problem is, that for example on phone1 my widget has NO margins (it's like sticked to screen borders) and on other phones it has automatic margins like it should. When I add my own margin to widget provider, it has this margins on phone 1, but on other phones it has (my margins + automatic margins). Hope, now it's clear :)

Welcome to Reality show, when the Android it isn't platform independent, either Java it isn't.
For this reason a single android layout.xml should use elements which are doing layout acceptable in all targeted devices. The screen ratio differs, the dpi differs the resolution differs... As best practice:
use dp size instead of pixels
do different layout for portait and landscape case
have multiple folders based on screen size ( and different layout)
I hope it helps!

well, to close this answer - it looks like there is really no option to have same margin on all devices - as different devices uses different home screen implementation. I can't do anything with that...Closed.

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

Android - layout directory in large density (2.25)

I have a strange bug on Samsung Galaxy Tab E (Nougat 7.0 API 24): I have 2 layout directory (layout and layout-sw600dp) when I change the "Screen Zoom" on the "Settings" to "Huge" the device for some reason is taking the XML from the "layout" directory and not from the "layout-sw600dp", for all the others density it works perfectly except the this one.
Is there a solution for this bug?
It's not only in Galaxy devices but you can have this in any device exceeding the sw system.
So instead of making specific folders like layout-sw600 etc, I recommend you to make specific layouts using ConstraintLayout.
ConstraintLayout not only makes your layout flexible but also adjusts it's size based on the increase or decrease in Density Pixels of the devices and also saves your. Development Time. I faced a similar issue long time back and decided to use ConstraintLayout for the same.
A good codelab from Google on ConstraintLayout can be found here:
https://codelabs.developers.google.com/codelabs/constraint-layout/index.html?index=..%2F..%2Fio2018#0
Hope it helps. Good luck.
The system will use the one which is closest to (without exceeding) the device's smallestWidth, but when Screen Zoom set to Huge, the smallest width of device exceeds 600dp.
And your layout files only have two folders (layout and layout-sw600dp), so finally the system choose the layout folder.

android UI inconsistent between phones

In the app I am working on, there is inconsistency between what is displayed in the Android Studio UI builder and the 2 phones I tested it on (A nexus 6p and an Xperia XZ Premium. They both have the same aspect ratio, with the 6p being 2560x1440 and XZ being 3840x2160 but scaled down to 1920x1080 during normal use if I understand correctly)
For instance: I have 3 buttons with a static width in dp at the top of the screen in a constraintlayout, and in the UI builder they go from one end of the screen to the other, each constrained to the left and evenly spaced. In the builder and on the 6p, it displays properly. However, on the XZ, it is but off.
After further testing, it seems the XZ always cuts off around 25dp on the right and bottom when the layout contains objects with set widths and lengths that cross into those missing 25dp. How do I fix this? The 6p displays everything just fine
Try using auto layout constraints to help adjust the dimensions. Something you should consider for the future is that you need move fragments, that will insure consistent UI over many versions of android phones and tablets currently in the market.
Android layout view can help you do all that.
Right click not the textfield/button that you want to set to a specific constraint and let the magic happen.

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.

Getting minWidth (appwidget-provider) across all devices, phones and tablets

My android application (Banner) uses widgets sizes from 1x1 to 8x1. I'm getting annoyed with trying to get the magic minWidth set in the XML appwidget-provider files.
Old school method to get widget minimum size was something like [74 x (n) - 2]. Now the method is [70 x (n) - 30]. Neither of these work well past 3x1 widgets. 4x1 if set correctly on a phone usually becomes a 3x1 widget on tablets because of dpi/density/size, etc.
So I ended up placing xml files as such to adjust width as needed. However, I'm really only guessing that the increased minWidth works with all devices as I only tested on my own tablet.
So my question is this... has anyone figured out the BEST minWidths or methods for making widgets on different device sizes, etc?

Categories

Resources