Widget wrong grid size - android

I've written a widget which is supposed to be 4x2 homescreen blocks. It's minheight and minwidth, with accordance to the current "App Widget Design Guidelines" page are
android:minWidth="250dp"
android:minHeight="110dp"
And a padding is applied from dimens.xml if the system version is below Ice Cream Sandwich
On my Nexus 4 (xhdpi, Jellybean 4.2.1), this widget is 4x2. On an emulator (hdpi, Gingerbread 2.3.3), this widget is 4x2. On my Nexus 7 however (hdpi, Jellybean 4.2.1), the widget is 3x2. I can't for the life of me figure out why or how to fix it. Any thoughts?

Lars Vogel writes in this Home Screen Widget tutorial that:
As a calculation rule you should define the size of the widget with the formula: ((Number of columns / rows)* 74) - 2. These are device independent pixels and the -2 is used to avoid rounding issues.
Edit: apparently Vogel got it from the old Widget API documentation (scroll down past mid page to see reference).
Based on this measurement, for a 4 cells width and 2 cells height, use 294 x 146 dip:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dip" android:minHeight="146dip"
android:updatePeriodMillis="0" android:initialLayout="#layout/some_layout" />

Related

Widget looks different on different phones

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.

4x4 appwidgets are detected as 3x3 on tablets

I create an 4x4 appwidget with minWidth and minHeight set to "250dp" as it is suggested in
App Widget Design Guidelines:
http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
It is ok on every phones and phone-sized emulator I have tried but if I test it on a tablet (Xoom or Nexus 7) or on an emulator (resolution: 1280x752 with dpi 160)
then the launcher detects it as 3x3 widget.
What am I doing wrong?
Thanks,
Tamas
Try grid size = (74*n) - 2 for older api level. This value come from old document.

What sizes to use for a 4x2 appwidget

I'm trying to create an appwidget that has a standard size of 4x2 tiles.
Currently, I'm using these values:
android:minHeight="146dp"
android:minWidth="294dp"
On my Desire running Gingerbread, the widget shows as 4x2.
On my Asus TF101 tablet running ICS, the widget gets a size of 4x2.
Finally, in an emulator 720x1280 running ICS, the widget gets a size of 4x3.
So I'm a bit confused here. What are the correct values (perhaps using different resource folders) to achieve a 4x2 widget on all devices?
I've found that working on approx. 72dp x 72dp per 1x1 works best. So for a 2x2 widget I would normally use 144dp x 144dp, however google recommends 110dp x 110dp.
This page from Google gives a better description of what size to use and how to calculate it:
http://developer.android.com/guide/practices/ui_guidelines/widget_design.html
According to google guidelines you should use this formula : 70 × n − 30
For a 4*2 widget that means you should use 250dp * 110dp.
More infos : http://developer.android.com/guide/practices/ui_guidelines/widget_design.html

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

Home screen widget size for large screen or hdpi?

From Android widget screen guidelines, http://developer.android.com/guide/practices/ui_guidelines/widget_design.html, we know that, home screen has 4*4 cells, and in portrait orientation, each cell is 80 pixels wide by 100 pixels tall.
I think these are for baseline HVGA screen. How about for large screens and hdpi screens, do they still have 4*4 cells for widget and each cell in portrait orientation is still 80 pixels * 100 pixels?
Thanks.
The pixels you are referring to are device independent pixels. As you can see in the documentation here:
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="86400000"
android:initialLayout="#layout/example_appwidget"
android:configure="com.example.android.ExampleAppWidgetConfigure" >
</appwidget-provider>
Note how they are using dp units, not px. This allows the widget to scale correctly to different screen resolutions.
As for the screen being 4x4 cells, this is a property of the default Android homescreen manager. Regardless of screen resolution the home screen will be 4x4 cells when using the default Android home screen.
There are other home screen managers out there that have more than 4x4 cells, such as the custom home screen manager on the Archos tablets. If you want your appwidget to work in some of these other homescreen managers that do special things like increase the number of cells on the screen or allow text input and scrolling in app widgets, then you are probably going to have to write a custom version of your widget for those home screen managers.
So the answer to your question, assuming you are always targeting the default home screen manager, is that the screen is always 4x4 cells and as long as you stick with device independent pixels you have nothing extra you need to do to make your appwidget scale and work correctly on higher resolutions.
When you use images, you have to put them with different dimensions into the related folders in your project-directory.
example:
- you use 100dip width for an imageview
- in folder "drawable-mdpi" you should put .png with 100px width.
- in folder "drawable-hdpi" .png with 150px width
- in folder "drawable-ldpi" .png with 75px width

Categories

Resources