我正在寻找一种在我的小部件启动时绘制加载图标(例如圆形条)的方法。 默认情况下,我使用appwidget-provider xml资源文件中描述的初始布局: (android:initialLayout xml元素)
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="144dp"
android:initialLayout="@layout/widget_message"
android:configure="fr.cdcorp.homewidget.configurationActivity.WDWidgetConfiguration"
android:updatePeriodMillis="43200000"
/>
因此,在这个初始布局(widget_message.xml)中,我使用了一个ImageView,其中src是一个动画GIF圆形条。 但是,这不起作用,我只看到gif的第一帧,而不是动画Gif。 AFAIK这可以做到,Fancy Widget做到了。 任何帮助将是欣赏! 谢谢, C.D
答案 0 :(得分:0)
final class GIFView extends View {
Movie movie, movie1;
InputStream is = null, is1 = null;
long moviestart;
public GIFView(Context context) {
super(context);
is = context.getResources().openRawResource(R.drawable.youranimatedgif);
movie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
try{
long now = android.os.SystemClock.uptimeMillis();
if (moviestart == 0) { // first time
moviestart = now;
}
int relTime = (int) ((now - moviestart) % movie.duration());
System.out.println("time=" + relTime + "\treltime=" + movie.duration());
movie.setTime(relTime);
//this will draw on the top left corner of your display
movie.draw(canvas, 0,0);
this.invalidate();
}
catch (Exception e) {
//make you stuff here
}
}
}
public class YuorActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try{
setContentView(new GIFView(this));
new InitTask().execute(this);
}
catch (Exception e) {
//do your stuff here
}
}
}
希望这有帮助...