无法在小部件中使用表格布局?
这是我的 Android 小部件的 xml 文件:(
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<!-- Some views -->
</TableRow>
<TableRow>
<!-- Some views -->
</TableRow>
</TableLayout>
</LinearLayout>
完整代码位于:http://pastebin.com/Kqxs5t9E )
这段代码在 Eclipse 中向我展示了一些好的结果,但是当我将文件发送到我的设备并尝试将小部件添加到我的主屏幕时,我收到此错误代码并且小部件显示:“加载小部件时出现问题”:
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): updateAppWidget couldn't find any view, using error view
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.widget.RemoteViews.apply(RemoteViews.java:930)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:155)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:218)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.bindAppWidgets(Launcher.java:3652)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.access$22(Launcher.java:3639)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher$DesktopBinder.handleMessage(Launcher.java:4625)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Looper.loop(Looper.java:123)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at dalvik.system.NativeStart.main(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): Caused by: android.view.InflateException: Binary XML file line #20: Class not allowed to be inflated android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:472)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): ... 20 more
所以什么?我无法在小部件中使用表格布局???
那么最好的解决方案是什么?我可以创建很多相对布局,但我想这不是一个好主意。
Here is the xml file of my Android widget:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<!-- Some views -->
</TableRow>
<TableRow>
<!-- Some views -->
</TableRow>
</TableLayout>
</LinearLayout>
(full code here: http://pastebin.com/Kqxs5t9E)
This code is showing me some good results in Eclipse, but as soon as I sent the file to my device and try to add the widget to my homescreen I get this error code and the widget showing: "Problem Loading the Widget":
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): updateAppWidget couldn't find any view, using error view
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): android.view.InflateException: Binary XML file line #20: Error inflating class android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.widget.RemoteViews.apply(RemoteViews.java:930)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:219)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:155)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:218)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.bindAppWidgets(Launcher.java:3652)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher.access$22(Launcher.java:3639)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.fede.launcher.Launcher$DesktopBinder.handleMessage(Launcher.java:4625)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Handler.dispatchMessage(Handler.java:99)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.os.Looper.loop(Looper.java:123)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invokeNative(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at java.lang.reflect.Method.invoke(Method.java:521)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at dalvik.system.NativeStart.main(Native Method)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): Caused by: android.view.InflateException: Binary XML file line #20: Class not allowed to be inflated android.widget.TableLayout
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:525)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): at android.view.LayoutInflater.createView(LayoutInflater.java:472)
08-01 22:11:26.917: WARN/AppWidgetHostView(5860): ... 20 more
So what? I cannot use a Tablelayout within a widget????
What is the best solution so? I can create a lot of relativelayout but I guess that's not a good idea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果“小部件”指的是“应用程序小部件”,那么,不,您不能在应用程序小部件中使用
TableLayout
。 应用小部件中只能使用少数小部件。我不知道你为什么认为
RelativeLayout
不好。您可以用单个RelativeLayout
替换LinearLayout
、TableLayout
和TableRow
小部件。If by "widget" you mean "app widget", then, no, you cannot use a
TableLayout
in an app widget. There are only a few widgets that can be used in an app widget.I do not know why you think
RelativeLayout
is bad. You may be able to replace yourLinearLayout
,TableLayout
, andTableRow
widgets with a singleRelativeLayout
.