【发布时间】:2012-10-29 11:45:56
【问题描述】:
我有一个带有小部件的应用程序。我知道 Android 4.0 或更高版本会自动在小部件周围创建一个边距,因此我在 this developers API page 上实施了建议,以使不同 Android 版本上的小部件大小大致相同。我已经在 API 10、14 和 15 上的模拟器中测试了这个小部件,它工作正常。该小部件在所有版本中看起来都相同。但是,当我在装有 Android 4.0.3 的 SGS2 手机上测试它时,没有边距!怎么会这样?我错过了什么?有其他人经历过这种行为吗?
!
这是我的 res/xml/widget_info.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:initialLayout="@layout/widget"
android:minHeight="40dp"
android:minWidth="110dp"
android:updatePeriodMillis="60000" >
</appwidget-provider>
res/layout/widget.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget_mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/widget_margin"
android:background="@drawable/widget_background" >
</RelativeLayout>
res/drawable/widget_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#222222" />
<gradient
android:angle="225"
android:startColor="#DD2ECCFA"
android:endColor="#DD000000" />
<corners android:radius="7dp" />
</shape>
res/values/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="widget_margin">8dp</dimen>
</resources>
res/values-v14/dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="widget_margin">0dp</dimen>
</resources>
起初我认为这与小部件没有按照here 的描述正确更新有关,但删除小部件并再次添加它并没有帮助。我还尝试了一些设置:
- 在
widget_info.xml文件中设置maxHeight和maxWidth不起作用,模拟器和手机似乎都忽略了。 - 将
widget.xml文件中的layout_margin更改为padding无效,小部件看起来相同(但在模拟器API10 上的小部件现在也没有边距) - 将
res/values-v14/dimens.xml文件中的0dp更改为16dp确实对手机和模拟器都有影响,但手机和模拟器上的小部件大小仍然不同。
编辑: 我已经在手机上安装了 GO Launcher Ex,然后小部件确实有边距,所以我想这是三星 TouchWiz 启动器的特定问题?谁能证实这一点?我也对使用 TouchWiz 时使小部件看起来(或多或少)相同的解决方案感兴趣。
【问题讨论】:
-
SGS 启动器应用与默认的 android 启动器不同。用市场上的另一个启动器试试看结果是否相同。
-
@wingman 谢谢你的信息,我已经修改了我的帖子。
-
您无法保证最终用户可能拥有什么样的启动器。执行此类要求的唯一方法是故意为填充添加虚拟透明元素,而不是边距。
标签: android layout android-widget