4x4 appwidgets are detected as 3x3 on tablets - android

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.

Related

Which emulator should I use for a Huawei Y300 and Y530?

I am trying to emulate a Huawei Y530. According to this site, it has the following specifications:
Screen: 480 x 854 pixels, 4.5 inches (~218 ppi pixel density)
This is what my WEB APP looks like on the actual device:
And this is what it looks like on a emulator, with the following specification:
Target: Android 4.3 - API Level 18
Device: 4" WVGA (Nexus S) (480x800 hdpi)
I know there is a difference in the height of the two devices, but still I believe that the emulator should show something similar to what the actual device is showing.
I tried to find the innerWidth and innerHeight of the real device with the following code:
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth,
viewportheight = window.innerHeight
}
alert (viewportwidth);
alert(viewportheight);
The result is width: 320px and height: 544px
The innerWidth on the emualtor is: 480px and the innerHeight: 756px
Since the real device had a width of 320px, i tried using an emulator with the following specs:
Screen: 3.2" QVGA (ADP2) (320 x 480 mdpi)
With the following result:
You can always create a new emulator if the app will be developed only for this particular phone. The image attached emulates the exact properties of the Huawei Ascend Y530 phone.
Alternatively, if the app is being developed for different phone having different screen sizes, I would take a look at the xml file for the layout. Take note of the following attributes, like placing form widgets in relation to other widgets. For example: android:layout_toRightOf="#+id/ukFlag" for the Danish flag. There are actually several layout parameters you can paly around with until you get the right layout:
Layout_toLeftOf
Layout_toRightOf
Layout_above
Layout_below
You can also setup the positioning of the widget, to be either left_based, right_based or centred.
Hope this would help you better: Android Layouts
Without knowing too much in how you have done your application, it seems you are using fixed units like pixels to specify size. As this project is a web app, maybe you should consider to use what is called a Responsive Design approach. In that way your content can adjust to whatever size the screen is.
I'll let you a couple of useful articles to learn more about this:
Responsive Web Design in Wikipedia
Responsive Design Presentation
Responsive Design Examples

Android: how to calculate dpi from a design?

I have a 800 x 480 (landscape) design made in photoshop and now I'm trying to implement the same design on Android.
How am I supposed to calculate width and height for a LinearLayout? For example, a header has 800px width and 60px height. How many DPI they are?
The min and the target SDK are 14. Am I need to worry for devices that are using a smaller display? (Smaller than 480x800) ? (I don't know if older devices can run Android 4+)
I have tested on my AVD (Nexus 7) and this is how it's look (accordingly to my photoshop design):
But on a tablet:
Am I need to create different layouts for different devices?
First thing that you need to understand - for which density your design is. Most common situation is design in mdpi, which means that 1dp on device (with mdpi screen) will be equivalent to 1px of design layout. On devices with higher density it will be increased accordingly (4:6:8 rule).
Second thing - providing values in dp won't magically scale up your layout for larger devices. Note, that dpi is not the same as screen resolution. So, for example, large 10inch tablet with 1280x800 screen resolution is mdpi device (not hdpi, not xhdpi).
Third. It makes no sense to say "800x600 device is smaller that 1280x800", because they may both be, for example, 4inch phone.
Fourth. Screen resolution have nothing to do with SDK version.
What you need to do, is look for another design for larger devices or ask designer about what he wanted to see. Maybe images shouldn't be strictly sized in dp, maybe they should be sized in percentage of the occupied screen?

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

Appwidget size calculation

It might be me, but when I calculate minimum app widget sizes according to the formula given on the android page I don't get the right widget widths; The formula is as follows:
width(n) = (70 x n) - 30
When I want to have a 5x1 widget, the correct width would be (5 * 70) - 30 = 320dp. However when testing this on a motorola Xoom it resolves to being a 4x1 widget. I've tested different values and 400dp seems good for 5x1 on the motorola xoom with Honeycomb, but then I'd test it on a regular Galaxy Tab with Gingerbread and then it resolves to a 6x1 (like one would expect).
So two questions here;
What difference between Gingerbread and Honeycomb am I overlooking?
Since I know ICS widget size no longer has padding between widgets, is there some rule of thumb here as well?
In my 4x1 widget, I used these dimensions for res/values/dimens.xml:
<!-- size = (74 x n) - 2 -->
<dimen name="appwidget_margin">0dp</dimen>
<dimen name="appwidget_min_width">294dp</dimen>
<dimen name="appwidget_min_height">72dp</dimen>
and for res/values-v14/dimens.xml:
<!-- size = (70 x n) - 30 -->
<dimen name="appwidget_margin">0dp</dimen>
<dimen name="appwidget_min_width">250dp</dimen>
<dimen name="appwidget_min_height">40dp</dimen>
I used widget templates pack for background images .
In official guide there is written that default margin in res/values/dimens.xml should be 8dp, but if I use 8dp, my widget is smaller than standard widgets on the desktop (google search, weather etc.). Thats's because margin for v1-v13 is built in the background image:
I tested it on HTC Desire, Nexus S, emulator Android 2.2 and emulator Android 2.3.3. With the templates pack backgrounds and configuration above, my widget's size is the same as other standard widgets and looks good on all devices I tested.
There is also problem with various launchers. I recommend this article to read: http://radleymarx.com/blog/app-widget-padding-margins-in-ics-android/
Not too many devices fully follow Google's advised formula. You're better off using several xml-xxx folders that can specify more accurate minWidth & minHeight that correspond to the varying screens & OSes.
Right now I four solely based on OS:
xml // standard
xml-v11 // Honeycomb grid
xml-v14 // ICS's new extra padding
xml-sw552dp-v14 // ICS tablet padding
But as I fine tune, I may have to add a few new folders for particular dpis or screens.
Quick update:
Only some devices use automatic padding. Samsung & HTC have custom UIs that use full-width widgets, so they override the OS padding on their launchers.
In ICS there isn't no padding, there is automatic padding. And the formula that you used is for ICS.
For older versions there is another formula:
num*74 - 2
note: if you target pre-Honeycomb (or don't specify targetSdkVersion while specifying a minSdkVersion prior to honeycomb) then the honeycomb grid (and ICS grid) calculations don't take effect. Downside of this is you miss out on newer OS features, but if you don't actually need them then keeping target pre-honeycomb will save the hassle of customised xml folders.

Android Tablet Dimensions

We have just started Android Tablet development. I need to prototype for 7in and 10in tablets.
Is there any wireframe stencil i can get hold of ?
What are the dimensions of the canvas i need to start designing on ?
Just like phones, tablets have all sorts of dimensions and sizes.
Here is a quick list of different models with their respective sizes and dimensions:
Samsung Galaxy Tab 10.1 3G - 10.1 inches, 1280 x 800 pixels
Samsung P1000 Galaxy Tab - 7.0 inches, 600 x 1024 pixels
Dell Streak 7 - 7-inch 800×480
Motorola Xoom - 10.1-inch, 1280×800
Viewsonic G - 10.1-inchs 1024×600
These are the dimensions you'll find most often.
Rather than considering actual pixel dimensions (which can vary in size depending on pixel density), it might be easier to think in density independent pixels (dp). This is the smallest device width as given in the configuration examples from the docs:
7” tablet: 600dp
10” tablet: 720dp
Notes
For actual pixels size, multiply by 1 to get mdpi, multiple by 2 to get xhdpi, by 3 to get xxhdpi, etc. See here for more.
To provide different resources for the various screen sizes, see this answer.
Old topic but i think i've got a good way to resolve your probleme. If it can help some..
First of all, if you do right, All your activities should be composed ONLY with fragments.
You may know that when a screenSize is defined as exemple by 384* 640, that means your maxWidth is 384dp and your maxHeight is 640dp.
And so, it's easy to determine how height you should use without trying on emulator.
Still using my screenSize exemple : 384 (Widht) * 640 (Height) :
640dp
292dp
264dp '
<dimen name="max_height">640dp</dimen> <!-- screen maxHeight -->
<dimen name="half_height">292dp</dimen> <!-- ScreenMaxHeight with actionBar -->
<dimen name="half_height_bigactionbar">264dp</dimen> <!-- height without actionBar and its subActionBar -->
Down here, this is my fragment size :
<fragment
android:layout_width="match_parent"
android:layout_height="#dimen/half_height_bigactionbar"
Both of my fragmennts should now fill all the sreen
My action bar height is 56dp . If you do the map if i want he half of my screen i do ((maxScreenHeight) - (ToolBarSize) ) / 2.
I got ((640) - (56)) / 2 = 292dp !
Do the same for All of resolution you might know with all the window part you may use:
And you will have THE perfect match in every phone you know.
You can do the same math for width if you use tablet.
But remember, use as much as possible wrap_content + marginLeft and MarginRight to place your components !
When you wana create an activity. Draw it in a sheetwith small-paned . And think only with percent. Then do the math, and use ONLY fragments.
You should be fine then :). Ask if i wasn't clear enought !

Categories

Resources