我很难将支持库与android.support.v7.widget.GridLayout
. 它总是给我以下错误:
08-09 23:49:55.746: W/AppWidgetHostView(132): Error inflating AppWidget AppWidgetProviderInfo(provider=ComponentInfo{com.myapp.AppWidget}): android.view.InflateException: Binary XML file line #33: Error inflating class android.support.v7.widget.GridLayout
08-09 23:49:56.716: W/AppWidgetHostView(132): updateAppWidget couldn't find any view, using error view
08-09 23:49:56.716: W/AppWidgetHostView(132): android.view.InflateException: Binary XML file line #33: Error inflating class android.support.v7.widget.GridLayout
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.widget.RemoteViews.apply(RemoteViews.java:939)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.appwidget.AppWidgetHostView.updateAppWidget(AppWidgetHostView.java:218)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.appwidget.AppWidgetHost.updateAppWidgetView(AppWidgetHost.java:250)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.appwidget.AppWidgetHost$UpdateHandler.handleMessage(AppWidgetHost.java:73)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.os.Looper.loop(Looper.java:123)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-09 23:49:56.716: W/AppWidgetHostView(132): at java.lang.reflect.Method.invokeNative(Native Method)
08-09 23:49:56.716: W/AppWidgetHostView(132): at java.lang.reflect.Method.invoke(Method.java:507)
08-09 23:49:56.716: W/AppWidgetHostView(132): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-09 23:49:56.716: W/AppWidgetHostView(132): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-09 23:49:56.716: W/AppWidgetHostView(132): at dalvik.system.NativeStart.main(Native Method)
08-09 23:49:56.716: W/AppWidgetHostView(132): Caused by: java.lang.ClassNotFoundException: android.support.v7.widget.GridLayout in loader dalvik.system.PathClassLoader[.]
08-09 23:49:56.716: W/AppWidgetHostView(132): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-09 23:49:56.716: W/AppWidgetHostView(132): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-09 23:49:56.716: W/AppWidgetHostView(132): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.createView(LayoutInflater.java:471)
08-09 23:49:56.716: W/AppWidgetHostView(132): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
08-09 23:49:56.716: W/AppWidgetHostView(132): ... 15 more
提到的第 33 行是 support lib 标签开始的部分。似乎由于某种原因找不到该课程,但我不知道为什么...
我想使用这个库的原因是因为我想与 Android v10 保持兼容。不管我选择 v10 还是 v4.2.2 作为项目构建目标。清单minSdkVersion
设置为 10。我按照所有这些步骤进行操作,并尝试将 .jar 放入应用程序的引用库中并勾选导出它的选项。
这是我layout.xml
的,用于创建应用程序小部件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/appWidget_relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<TextView
android:id="@+id/appWidget_textView_profileName"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="false"
android:enabled="true"
android:gravity="center_horizontal"
android:longClickable="true"
android:scrollHorizontally="false"
android:text="profile name"
android:textAppearance="?android:attr/textAppearanceLarge" />
<FrameLayout
android:id="@+id/appWidget_frameLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/appWidget_textView_profileName" >
</FrameLayout>
<android.support.v7.widget.GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</android.support.v7.widget.GridLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</RelativeLayout>
更新:我设法将其缩小到GridLayout
与应用小部件相关的使用范围。似乎,只有在您使用GridLayout
它们时才会出现此问题。当我对普通人使用相同的布局时,Activity
它可以正常工作。关于如何解决这个问题的任何建议?