我想使用非常简单的GridLayout
构建一个小部件,但我收到了一个InflateException:
Binary XML file line #2: Error inflating class android.widget.GridLayout
只发生在4.0和4.2上是没有问题的工作(版本之间有区别吗?) 有人知道一些事情吗?
堆栈跟踪
03-12 12:27:49.100: W/AppWidgetHostView(528): updateAppWidget couldn't find any view,
using error view
03-12 12:27:49.100: W/AppWidgetHostView(528): android.view.InflateException: Binary XML file line #2: Error inflating class android.widget.GridLayout
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.RemoteViews.apply(RemoteViews.java:1581)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:289)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.appwidget.AppWidgetHost.createView(AppWidgetHost.java:238)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.home.widget.WidgetManager.getWidgetView(WidgetManager.java:142)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.home.layer.AdapterHelper.getWidgetInfoView(AdapterHelper.java:280)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.home.layer.desktop.DesktopAdapter.getView(DesktopAdapter.java:100)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.paneview.PaneView.ensureItemView(PaneView.java:2343)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.paneview.PaneView.layoutItem(PaneView.java:2294)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.sonyericsson.paneview.PaneView.onLayout(PaneView.java:1199)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:930)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:930)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:930)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:930)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1653)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1511)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.LinearLayout.onLayout(LinearLayout.java:1416)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.widget.FrameLayout.onLayout(FrameLayout.java:444)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.View.layout(View.java:11390)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewGroup.layout(ViewGroup.java:4332)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1490)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2455)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.os.Handler.dispatchMessage(Handler.java:99)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.os.Looper.loop(Looper.java:137)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.app.ActivityThread.main(ActivityThread.java:4424)
03-12 12:27:49.100: W/AppWidgetHostView(528): at java.lang.reflect.Method.invokeNative(Native Method)
03-12 12:27:49.100: W/AppWidgetHostView(528): at java.lang.reflect.Method.invoke(Method.java:511)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
03-12 12:27:49.100: W/AppWidgetHostView(528): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
03-12 12:27:49.100: W/AppWidgetHostView(528): at dalvik.system.NativeStart.main(Native Method)
03-12 12:27:49.100: W/AppWidgetHostView(528): Caused by: android.view.InflateException: Binary XML file line #2: Class not allowed to be inflated android.widget.GridLayout
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.failNotAllowed(LayoutInflater.java:618)
03-12 12:27:49.100: W/AppWidgetHostView(528): at android.view.LayoutInflater.createView(LayoutInflater.java:558)
03-12 12:27:49.100: W/AppWidgetHostView(528): ... 49 more
布局XML
<?xml version="1.0" encoding="utf-8"?>
<GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:useDefaultMargins="true"
android:alignmentMode="alignBounds"
android:columnOrderPreserved="false"
android:columnCount="4"
>
<TextView
android:text="Email setup"
android:textSize="32dip"
android:layout_columnSpan="4"
android:layout_gravity="center_horizontal"
/>
<TextView
android:text="You can configure email in just a few steps:"
android:textSize="16dip"
android:layout_columnSpan="4"
android:layout_gravity="left"
/>
<TextView
android:text="Email address:"
android:layout_gravity="right"
/>
<EditText
android:ems="10"
/>
<TextView
android:text="Password:"
android:layout_column="0"
android:layout_gravity="right"
/>
<EditText
android:ems="8"
/>
<Space
android:layout_row="4"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="fill"
/>
<Button
android:text="Next"
android:layout_row="5"
android:layout_column="3"
/>
package com.path.testwidget;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.widget.RemoteViews;
public class TestWidget extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
RemoteViews rvs= new RemoteViews(context.getPackageName(), R.layout.balance_widget);
//update all N widgets
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
appWidgetManager.updateAppWidget(appWidgetId, rvs);
}
}
}
答案 0 :(得分:4)
RemoteView 只允许在其内容中夸大某些布局,您可以看到列表here
例如,您可以看到不允许使用 TableView 。 你的logcat消息说不允许 GridView ,而文档说它是。 我想这个功能很新,并且不允许在4.2之前的版本上使用。或4.1。
您应该在远程视图中使用其他布局类型。