对于小部件,我使用包含TableLayout
的简单布局<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow >
(...)
</TableRow>
</TableLayout>
但是当我想通过创建RemoteViews
RemoteViews eventElementLayout = new RemoteViews( this.getPackageName(), R.layout.widget_events_element );
我得到一个例外,告诉我TableLayout
不允许被夸大。
12-04 01:36:12.548: WARN/AppWidgetHostView(195): updateAppWidget couldn't find any view, using error view
12-04 01:36:12.548: WARN/AppWidgetHostView(195): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.TableLayout
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.apply(RemoteViews.java:930)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews$ViewGroupAction.apply(RemoteViews.java:513)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.performApply(RemoteViews.java:955)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.widget.RemoteViews.apply(RemoteViews.java:932)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.os.Handler.dispatchMessage(Handler.java:99)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.os.Looper.loop(Looper.java:123)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at java.lang.reflect.Method.invokeNative(Native Method)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at java.lang.reflect.Method.invoke(Method.java:521)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at dalvik.system.NativeStart.main(Native Method)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): Caused by: android.view.InflateException: Binary XML file line #2: Class not allowed to be inflated android.widget.TableLayout
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): at android.view.LayoutInflater.createView(LayoutInflater.java:472)
12-04 01:36:12.548: WARN/AppWidgetHostView(195): ... 19 more
为什么?
提前致谢
答案 0 :(得分:20)
应用小部件仅允许可在其中使用的有限布局列表和视图小部件类型。看起来似乎不支持TableLayout
。来自Google开发人员documentation:
RemoteViews对象(和, 因此,一个App Widget)可以 支持以下布局类:
* FrameLayout * LinearLayout * RelativeLayout
以下小部件类:
* AnalogClock * Button * Chronometer * ImageButton * ImageView * ProgressBar * TextView
不支持这些类的后代。