开发者

Android: Widget takes too much place

开发者 https://www.devze.com 2023-03-06 16:05 出处:网络
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.

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" 
    andr开发者_JAVA技巧oid: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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号