Appwidget size calculation

后端 未结 4 721
说谎
说谎 2020-12-12 17:34

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 foll

相关标签:
4条回答
  • 2020-12-12 18:11

    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.

    0 讨论(0)
  • 2020-12-12 18:16

    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:

    enter image description here

    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/

    0 讨论(0)
  • 2020-12-12 18:17

    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
    
    0 讨论(0)
  • 2020-12-12 18:29

    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.

    0 讨论(0)
提交回复
热议问题