我想开发一个小部件应用程序,其中我想做一些旋转动画的图像视图我很困惑与小部件提供程序类我正在尝试但我无法做到如果任何身体不要请解决我的问题。我完全发布我的代码
NSKeyedUnarchiver.setClass(className forClassName:name)
我的清单代码
public class Widget extends AppWidgetProvider{
String act;
private Handler start_handler ;
private AnimationDrawable analogClockBee_anim = null;
private ImageView clock4_bee_Image = null;
private Animation animation_bee = null;
RemoteViews myViews;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);
act=intent.getAction();
animation_bee = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation_bee.setRepeatCount(-1);
animation_bee.setDuration(35000);
animation_bee.setInterpolator(context, android.R.anim.linear_interpolator);
// clock4_bee_Image = (ImageView) findViewById(R.id.clock_bee_rotate_anim);
clock4_bee_Image.setBackgroundResource(R.drawable.bee_animation);
analogClockBee_anim = (AnimationDrawable)clock4_bee_Image.getBackground();
if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(act)) {
myViews=new RemoteViews(context.getPackageName(), R.layout.widget);
AppWidgetManager.getInstance(context).updateAppWidget(intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_ID), myViews);
}
myViews.setImageViewResource(R.id.clock_bee_rotate_anim, R.layout.widget);
start_handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
// TODO Auto-generated method stub
super.handleMessage(msg);
if(msg.what == 0)
{
analogClockBee_anim.start();
clock4_bee_Image.startAnimation(animation_bee);
}
}
};
new Thread(new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
try {
Thread.sleep(500);
Log.i("inside handler", "5");
start_handler.sendEmptyMessage(0);
Log.i("inside handler", "6");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
}
在动画文件夹中旋转动画
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<receiver android:name=".Widget" android:label="My Custom Clock Widget">
<intent-filter >
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/widget" />
</receiver>
</application>
</manifest>
动画可绘制文件夹xml文件
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false"
android:interpolator="@android:anim/linear_interpolator"
>
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="350"/>
</set>
清单引用的xml文件应用小部件提供程序
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bee_anim"
android:oneshot="false">
<item android:drawable="@drawable/bee_0" android:duration="50" />
<item android:drawable="@drawable/bee_1" android:duration="50" />
<item android:drawable="@drawable/bee_2" android:duration="50" />
<item android:drawable="@drawable/bee_3" android:duration="50" />
<item android:drawable="@drawable/bee_4" android:duration="50" />
<item android:drawable="@drawable/bee_5" android:duration="50" />
<item android:drawable="@drawable/bee_6" android:duration="50" />
<item android:drawable="@drawable/bee_7" android:duration="50" />
<item android:drawable="@drawable/bee_8" android:duration="50" />
<item android:drawable="@drawable/bee_9" android:duration="50" />
</animation-list>
布局小部件xml文件,其中包含模拟时钟小部件和要动画的图像视图
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="146dp"
android:minHeight="146dp"
android:updatePeriodMillis="0"
android:initialLayout="@layout/widget"/>
请一些人解决我在这个问题上遇到的问题。提前谢谢