Widget looks different on different phones - android

I have huge problem with my widgets. The problem is it looks different on different phones. Let me show you examples.
It should looks like this (on SGS2 with Android 4.3.1):
https://dl.dropboxusercontent.com/s/rno895pfcvp6t33/SGS2.png
On Galaxy Ace (with Android 2.3.3) there is little empty gap:
https://dl.dropbox.com/s/woe15ten9qxoq4f/SGAce.png
Finally my friends phone (sony xperia tipo) with Android 4.1 (same resolution like Galaxy Ace one):
https://dl.dropbox.com/s/admfg3tht3zxtzh/WDuOieP.png
Here is provider of big widget:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="#layout/widget_days_big"
android:minHeight="162dp"
android:minWidth="300dp"
android:updatePeriodMillis="1800000" >
</appwidget-provider>
Any ideas why something like this occurs?

You should read this first carefully: http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
(Columns or Rows)
Available Size (dp) (minWidth or minHeight)
1 40dp
2 110dp
3 180dp
4 250dp
Take into consideration different dpi's/resolutions/screen sizes, some phones might not have a screen "fit enough" to display the widget of your size -> minWidth 300dp....
What you are experiencing is normal behavior, you need to open your widgets xml layout and pay more attention to font size, paddings, margins etc... unfortuantelly you need to make the layout xml "properly" and test it, keep in mind you have ldpi,mdpi,hdpi,xhdpi layouts to help you if your widget doesnt turn out right on all phones with default layout.

Related

Different InfoWidget.xml for App Widget

i have a question about the app widget in android. I'm a litte bit confused, cause i define in the info xml (res -> xml) the values for width (250) and height (110) (http://developer.android.com/guide/practices/ui_guidelines/widget_design.html). Now i expected my Widget take the in the width 4 cells and in the height 2 cells.
I tested it with a Nexus S (HDPI), all works fine, i tested it with a Nexus 4 (XHDPI), all works fine, i tested it with an Samsung Galaxy Tab 10.1/Emulator tablets (MDPI), it doesn't work, Nexus7 (Emulator) (TVDPI) also it didn't work.
OK, I looked in the Menu and i see the system takes 3 and not 4 cells for the width.
Now my Question is there a way to define specific xml files for the tablets (please notice that i would support device with android 2.3.3) or am I missing something?
Have you tried putting your layout for the widgets into different folders, so that it will be rendered out differently on different screen sizes? For example, when supporting tablets you would have a layout-xlarge folder which contains the layout for your Widget on extra large screens. See here for more information about Tablet layouts.

how to set layout for different screen size in android

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.

Android layout preview

I am developing a tablet-only app and I put xml files for 10 inch tablets in /res/layout-sw720dp folder.
When I preview customized xml in eclipse, I select device as "10.1in WXGA (Tablet) (1280x800: mdpi) and everything is positioned just fine (note: certain elements need to be positioned by adding some margins (in dp) ... ), but when I run this app on samsung's galaxy tab this elements are not positioned as xml editor shows.
What could be the problem?
Read link 1 and link 2 and you will get idea about how android supports multiple screen sizes.
Better use wrap content or use layout_weight attribute instead of fixing the sizes, for more consistent look on all devices

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.

Android: Widget takes too much place

I faced with a strange problem with my widget size.
I decided to develop one simple widget with supporting of ldpi, mdpi, large-mdpi and hdpi screens.
At first I created xml/widget.xml where I defined the following:
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minHeight="146dip"
android:minWidth="220dip"
android:updatePeriodMillis="0"
android:initialLayout="#layout/widget"/>
So I expect that my widget will take 3x2 cells for all supported screens.
Then I designed several layouts, one for each screen type - ldpi, mdpi, large-mdpi and hdpi - where:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/Widget"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
...
</RelativeLayout>
So I expect that the widget size will fit 3x2 cells for all screens, not more, not less.
But currently when I run it on emulator (and real device too) I see that my widget takes
more than a half of a screen for all supporting screens - 4x3 cells if
to talk that the max size is 4x4 cells (as it described here:
http://developer.android.com/guide/practices/ui_guidelines/widget_design.html#sizes).
Even if I'll define exact layout_width and layout_height in my widget
layouts in dip it will still take 4x3 cells, just it's visible part
will have another size.
Well, looks like emulator not always refresh my app and that is why I saw my old dimensions instead of new. My friend also said that emulator usually doesn't update apps if using startActivityForResult. So in that case it is better to restart widget manually. Hope that will be helpfull for someone else :)
From http://developer.android.com/guide/topics/appwidgets/index.html
Because the Home screen's layout orientation (and thus, the cell sizes) can change, as a rule of thumb, you should assume the worst-case cell size of 74 pixels for the height and width of a cell. However, you must subtract 2 from the final dimension to account for any integer rounding errors that occur in the pixel count. To find your minimum width and height in density-independent pixels (dp), use this formula:
(number of cells * 74) - 2

Categories

Resources