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

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?

Related

How to know all the dimens.xml(hYYYdp) files I have to create to support all the screen sizes?

I am a little bit desperate because I'm trying to know how can I know the exact list of different dimens.xml(hYYYdp) I have to create in order to support all the screen sizes. I think I have already seen all the related questions to mine but none of them has helped me to solve this doubt. This is the most related question that hasn't solved my doubt: How to define dimens.xml for every different screen size in android? .
To give you some context. The reason of having different values according to the screen size is because I have a ConstraintLayout with some items that have Top and Bottom margin and in some devices that margin is not looking good. In this post I made, someone suggested me to use different margin values according to the screen size: How to solve TextView being cropped in small devices because of layout margin?
I have thought that as the margin is dependent of the height of the device (as I am using only Top and Bottom margin) I would have to create a list of different dimens.xml files according to the height of the device (hYYYdp).
The real concern I have is that I don't know how many dimens.xml files I have to create to support all the screen sizes. What I have been doing is creating some specific dimens.xml files that are working for specific devices, but I think there has to be a general list of all the dimens.xml files that have to be created to support all the screen sizes.
For example, what I have been doing is to look the test devices of Android Studio one by one and create specific dimens.xml files for them. This is the process I have followed to create a specific dimens file:
Example:
1- First I have seen the list of the test devices of Android Studio, for example let's take this one:
2- After this, I have calculated the dp of the height of this specific test device:
240x400px (ldpi) device. So the height's dp is = 400/(120(ldpi)/160)== 533.33dp
3- Finally, I have added the dimens.xml(hYYYdp) correspondent to this specific device with the specific margin value that is looking good:
I have repeated this process for most of the test devices of Android Studio but as a result, I have a list of specific devices but I think there will remain many devices without being supported as not all the Android devices are in the Android Studio test devices list. I hope you have understand what I am trying to explain.

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.

How to make layout compatible with different android devices in android studio?

I am designing an app with a .jpeg background and with text views on particular places on the screen. I designed this for my nexus 6 and used dp for the widths and heights of text views and margin-left and margin-top. What my understanding of dp is that it changes with every device according to screen size and density. So it should work on different phones according to the value of dp for them.
But this is not the case. When I run that app on a different phone (nexus 5) the layout is all messed up. I tried using the different resources and qualifiers for different screens (large, small, normal). But the problem still prevails. The app considers both nexus 6 and nexus 5 as large screens. How do i fix this?
this is not the best solution i guess.
i guess your layout is just on the layout folder. i don't know if the first device you tested the layout is large or small but what you should do is create another folder named layout-sw600dp. this folder is used by tablets. the folder layout is used my phones and smaller devices. you could also create the layout-land and layout-sw600dp-land folders for the landscape orientation.
dp do change depending on the device but if your layout gets messed up then i guess the layout called by that device doesn't fit its resolution. i guess dp becomes smaller if the device is bigger and vice versa.

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

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.

Widgets appear smaller in Eclipse than on the phone

I am currently putting together an application for my HTC Evo 3D phone which has a screen resolution of 960x540. I have set up a custom layout configuration for designing the interface at this resolution. When in this configuration the widgets (texts views, seek bars etc.) appear small and compact, sparse on the screen. Whereas when I launch the application on my phone the buttons are considerably larger and fill the screen more. Is there some setting in Eclipse that will allow me to view the layout in the editor exactly as it would appear on my phone, allowing for easier design of the interface.
Many thanks, Mat.
with relevant code would be easer to help, however, if you are using dp unit measure, sizes will change according to resolution:screensize, not just resolution. I think also a "wrap_content" given to a textview/button etc. would change in size, because font size would be in sp. So, look if there is any emulator configuration that fits real device resolution AND screen size.
Take a look here for more info about measure units.
EDIT
so are you seeing it in eclipse in the graphical layout of yourlayout.xml? on the top bar of that window there's a dropmenu for display configurations, change it to see the layout in different screens (I don't see any 960x540 btw). however, if you really want to develop for one single device is a matter, but if you're going to release the app for different devices, you need some strategy to make flexible layouts. this is very useful.

Categories

Resources