Android:小部件启动屏幕:像 Fancy Widget 一样绘制一个加载图标(例如圆形栏)

发布于 2024-11-14 09:04:29 字数 613 浏览 2 评论 0原文

我正在寻找一种在我的小部件启动时绘制加载图标(例如圆形栏)的方法。 默认情况下,我使用 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 做到了。 任何帮助将不胜感激! 谢谢, 光盘

I'm looking for a way to draw a loading icon (e.g circle bar) while my widget is launching.
By default, I use the initial layout described in appwidget-provider xml resource file :
( android:initialLayout xml element )

<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" 
/>

So, in this initial layout (widget_message.xml), I use an ImageView in which src is an animated GIF circle bar.
But, this doesn't work, I just see the 1st frame of the gif, not animated Gif.
AFAIK this can be done, Fancy Widget does it.
Any Help would be appreciate !!
Thanks,
C.D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2024-11-21 09:04:29

试试这个,它对我有用..
我使用通过单击 appWidge 启动的活动,但它也应该适用于您的配置活动)

    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
        }

    }

}

希望这有帮助...

try this, it worked for me..
i use an activity launched from on click of appWidge, but it should work for your configuration activity too)

    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
        }

    }

}

hope this help...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文