public class ImagActivity extends Activity { AssetManager assetManager=null; String []dec; int currentImg=0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_imag); final Button button=(Button)findViewById(R.id.imagButton); final ImageView imgBig=(ImageView)findViewById(R.id.imgBig); try { assetManager=getAssets(); dec=assetManager.list(""); }catch (IOException e){ e.printStackTrace(); } button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { InputStream inputStream=null; currentImg=(++currentImg)%dec.length; while(!dec[currentImg].endsWith(".jpg")) { currentImg=(++currentImg)%dec.length; } try{ inputStream=assetManager.open(dec[currentImg]); }catch (IOException e){ e.printStackTrace(); } BitmapDrawable ibitmapDrawable=(BitmapDrawable)imgBig.getDrawable(); if(ibitmapDrawable!=null&&!bitmapDrawablep.getBitmap().isRecycled()) { Bitmap bitmapTmp=ibitmapDrawable.getBitmap(); // bitmapTmp.recycle(); bitmapTmp=null; } imgBig.setImageBitmap(BitmapFactory.decodeStream(inputStream)); if(inputStream!=null){ try{ inputStream.close(); }catch (IOException e){ e.printStackTrace(); } } } }); } @Override protected void onDestroy() { super.onDestroy(); } }
版权声明:本文为博主原创文章,未经博主允许不得转载。