Code example for AnimationDrawable

Methods: setOneShot

0
	public final AnimationDrawable build() {
		try { 
			if (decoder == null) {
				throw new RuntimeException("No image");
			} 
			final AnimationDrawable animationDrawable = new AnimationDrawable();
			for (int i = 0; i < decoder.getFrameCount(); ++i) {
	            final Bitmap bitmap = decoder.getFrame(i);
	            final BitmapDrawable drawable = new BitmapDrawable(bitmap);
	            // Explicitly set the bounds in order for the frames to display 
	            final int width = (int) (bitmap.getWidth() * density + 0.5f);
				final int height = (int) (bitmap.getHeight() * density + 0.5f);
				drawable.setBounds(0, 0, width, height);
	            final int delay = decoder.getDelay(i);
				animationDrawable.addFrame(drawable, delay);
	            if (i == 0) {
	                // Also set the bounds for this container drawable 
	            	animationDrawable.setBounds(0, 0, width, height);
	            } 
			} 
			animationDrawable.setOneShot(false);
			return animationDrawable;
		} finally { 
			reset(); 
		} 
	}