我处于某种情况,我想从动态图像列表中显示动画.我想使用AnimationDrawable为此目的,但不幸的是我被卡住了:(我的代码是
ImageView globe = (ImageView) findViewById(R.id.globe); AnimationDrawable animation = new AnimationDrawable(); animation.setOneShot(true); Resources res = this.getResources(); while (from <= to) { String name = "globe_" + String.format("%03d",from); int globeId = res.getIdentifier(name,"drawable",this.getPackageName()); animation.addFrame(res.getDrawable(globeId),200); from++; } globe.setBackgroundDrawable(animation); globe.post(new Runnable(){ @Override public void run() { animation.start(); } });
解决方法
所以Animation.addFrame(Drawable frame,int duration)需要一个可以从Bitmap创建的drawable.
如果您的图像列表是动态加载的:
List<Bitmap> images; int duration = 200; for(Bitmap image: images){ BitmapDrawable frame = new BitmapDrawable(image); animation.addFrame(frame,duration); }
试试这个,一定要工作.