幀動畫代碼實現示例

    ImageView image = (ImageView) findViewById(R.id.frame_image);
        final AnimationDrawable anim = new AnimationDrawable();
        for (int i = 1; i <= 14; i++) {
            int id = getResources().getIdentifier("list_icon_gif_playing" + i, "drawable", getPackageName());//獲取本地drawable資源文件
            Drawable drawable = getResources().getDrawable(id);
            anim.addFrame(drawable, 60);
        }

        anim.setOneShot(false);
        image.setBackgroundDrawable(anim);

        anim.start();
相關文章
相關標籤/搜索