2012-03-09 21 views
0

我正在尝试为Android创建Widget。 它包含这样的文件:在AVD上未装载Widget

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中运行它并试图添加我的小部件时,它显示消息“问题加载小部件”。 LogCat在详细模式下不显示任何内容。那么,什么是错的?

回答

1
  1. 你需要在你的AppWidgetProvider实施onUpdate()

  2. 您的布局不起作用。你可以通过在一个活动中尝试你的布局来告诉它。您在LinearLayoutTextView上缺少android:layout_widthandroid:layout_height。此外,您还不清楚您的FrameLayout正在为您做什么。

+0

设置布局帮助,谢谢!如果没有直接设置,我认为它有默认值... – 2012-03-09 17:53:29