我写了一个应该是 4x2 主屏幕 block 的小部件。它的minheight和minwidth,按照现行的《App Widget Design Guidelines》页面都是
android:minWidth="250dp"
android:minHeight="110dp"
如果系统版本低于 Ice Cream Sandwich,则从 dimens.xml 应用填充
在我的 Nexus 4(xhdpi,Jellybean 4.2.1)上,这个小部件是 4x2。在模拟器(hdpi,Gingerbread 2.3.3)上,这个小部件是 4x2。然而,在我的 Nexus 7(hdpi,Jellybean 4.2.1)上,小部件是 3x2。我无法终生弄清楚为什么或如何解决它。有什么想法吗?
最佳答案
Lars Vogel 在 this Home Screen Widget tutorial 中写道那:
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.
编辑:显然 Vogel 从 old Widget API documentation 得到它(向下滚动到中间页面以查看引用)。
基于此测量值,对于 4 个单元格宽度和 2 个单元格高度,使用 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" />
关于android - 小部件错误的网格大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13834574/