Android AppWidget - 扩展视图时出错:无法解析索引处的属性
Android AppWidget - Error inflating view: Failed to resolve attribute at index
我有一个 AppWidget 产生了这个错误:
W/AppWidgetHostView: updateAppWidget couldn't find any view, using
error view
android.view.InflateException: Binary XML file line #2: Failed to
resolve attribute at index 1: TypedValue{t=0x2/d=0x7f01009a a=-1}
Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute
at index 1: TypedValue{t=0x2/d=0x7f01009a a=-1}
我可以看出错误是由布局的 inflation 引起的,我可以将其归因于在我的 RemoteViewsService.RemoteViewsFactory
子类中创建新的 RemoteViews
' getViewAt()
方法:
@Override
public RemoteViews getViewAt(int position) {
[…]
final RemoteViews views = new RemoteViews(getPackageName(),
R.layout.appwidget_list_item);
[…]
return views;
}
注释掉这一行可以消除这个特定的错误,但我无法弄清楚它引用的布局文件有什么问题。
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_view"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="@+id/item_name"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:paddingEnd="?listPreferredItemPaddingRight"
android:paddingStart="?listPreferredItemPaddingLeft"/>
</LinearLayout>
该错误是由于在 AppWidget 布局中使用主题属性(例如 ?listPreferredItemHeight
)引起的,isn't possible。这些是错误所指的 "unresolved attribute(s)"。
我有一个 AppWidget 产生了这个错误:
W/AppWidgetHostView: updateAppWidget couldn't find any view, using error view android.view.InflateException: Binary XML file line #2: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f01009a a=-1} Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f01009a a=-1}
我可以看出错误是由布局的 inflation 引起的,我可以将其归因于在我的 RemoteViewsService.RemoteViewsFactory
子类中创建新的 RemoteViews
' getViewAt()
方法:
@Override
public RemoteViews getViewAt(int position) {
[…]
final RemoteViews views = new RemoteViews(getPackageName(),
R.layout.appwidget_list_item);
[…]
return views;
}
注释掉这一行可以消除这个特定的错误,但我无法弄清楚它引用的布局文件有什么问题。
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_view"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="@+id/item_name"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_vertical"
android:paddingEnd="?listPreferredItemPaddingRight"
android:paddingStart="?listPreferredItemPaddingLeft"/>
</LinearLayout>
该错误是由于在 AppWidget 布局中使用主题属性(例如 ?listPreferredItemHeight
)引起的,isn't possible。这些是错误所指的 "unresolved attribute(s)"。