主屏幕小组件中的自定义布局

时间:2016-06-01 14:14:02

标签: java android widget

我正在开发一个具有许多不同大小按钮的主屏幕小部件。为了最大限度地利用空间,我想为这个小部件使用流布局(出于一些疯狂的原因,android没有本机实现)。

要解决这个问题,我尝试过使用第三方实现并自己实现布局,但是,在加载小部件时我总是遇到异常:

W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view
                                                android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class [redacted].FlowLayout
                                                Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class [redacted].FlowLayout
                                                Caused by: java.lang.ClassNotFoundException: Didn't find class "[redacted].FlowLayout" on path: DexPathList[[zip file "/system/priv-app/Velvet/Velvet.apk"],nativeLibraryDirectories=[/system/priv-app/Velvet/lib/arm64, /system/priv-app/Velvet/Velvet.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /system/lib64, /vendor/lib64]]

我的小部件布局看起来像这样:

<[redacted].FlowLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#09C"
android:padding="@dimen/widget_margin"
android:id="@+id/widgetRoot"
android:orientation="horizontal">


</[redacted].FlowLayout>

假设编辑的命名空间是正确的,有没有办法做我想要的,或者是否无法使用带有主屏幕小部件的自定义布局?

1 个答案:

答案 0 :(得分:1)

主屏幕小部件很受限制,它们不支持自定义布局:https://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout