我正在尝试为Android创建一个小部件。 它包含这样的文件:
RES / XML / widgetinfo.xml:
<?xml version="1.0" encoding="UTF-8"?>
<appwidget-provider
xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dip"
android:minHeight="146dip"
android:updatePeriodMillis="3600000"
android:initialLayout="@layout/main" />
RES /布局/ main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout >
<TextView android:text="My widget" />
</LinearLayout>
</FrameLayout>
的AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.justmad.thegame"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<receiver android:name="WidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widgetinfo" />
</receiver>
</application>
</manifest>
的src / com.test.WidgetProvider:
package com.test;
import android.appwidget.AppWidgetProvider;
public class WidgetProvider extends AppWidgetProvider {
}
但是当我在AVD中运行它并尝试添加我的小部件时,它会显示消息“Problem loading widget”。 LogCat在详细模式下不显示任何内容。那么,出了什么问题?
答案 0 :(得分:1)
您需要在onUpdate()
中实施AppWidgetProvider
。
您的布局不起作用。您可以通过在活动中尝试布局来说明这一点。您在android:layout_width
和android:layout_height
上遗漏了LinearLayout
和TextView
。此外,我们还不清楚您FrameLayout
正在为您做些什么。