Use simple pictures
Using the Drawable Object
Bitmap and Bitmapdrawable objects
Package Peng. Liu. Test;Import Android. App. Activity;Import Android. Content. Res. Assetfiledescriptor;Import Android. Content. Res. Assetmanager;Import Android. Graphics. Bitmapfactory;Import Android. Graphics. drawable. Bitmapdrawable;Import Android. Graphics. drawable. Clipdrawable;Import Android. Media. MediaPlayer;Import Android. OS. Bundle;Import Android. OS. Handler;Import Android. OS. Message;Import Android. View. View;Import Android. View. Animation. Animation;Import Android. View. Animation. Animationutils;Import Android. Widgets. ImageView;Import Java. IO. InputStream;Import Java. Util. Timer;Import Java. Util. TimerTask;public class Mainactivity extends activity{string[] Images;ImageView image;int currentimg;Assetmanager Asset;@Override protected void OnCreate (Bundle savedinstancestate) {Super. OnCreate(savedinstancestate);Setcontentview (R. Layout. Activity_main);Image = (ImageView) Findviewbyid (R. ID. Imagebit);try{asset = Getassets ();Images = Asset. List("");}catch (Exception e) {E. Printstacktrace();} Findviewbyid (R. ID. Btnbit). Setonclicklistener(New View. Onclicklistener() {@Override public void OnClick (view view) {if (currentimg >= images. Length) {currentimg =0;} while (!images[currentimg]. EndsWith(". png") &&!images[currentimg]. EndsWith(". jpg") &&!images[currentimg]. EndsWith(". gif")) {currentimg++;if (currentimg >= images. Length) {currentimg =0;} InputStream assetfile = null;try{assetfile = Asset. Open(images[currentimg++]);}catch (Exception e) {E. Printstacktrace();} bitmapdrawable drawable = (bitmapdrawable) image. Getdrawable();if (drawable! = null &&!drawable. Getbitmap(). isRecycled()) {drawable. Getbitmap(). Recycle();} Image. Setimagebitmap(bitmapfactory. Decodestream(Assetfile));} } });}}
Android Bitmap and Bitmapdrawable class parsing-android learning Journey (60)