2015-04-21 27 views
0

我從XML讀取。在ImageView中添加本地圖像

<movie> 
    <id>1</id> 
    <title>Fast</title> 
    <background>assets://icon/photography1</background> 
</movie> 

現在我已經得到了類Movie

如何在我的ImageView中添加assets://icon/photography1

+0

你可以用java代碼來完成它。 – Amy

+0

看到http://stackoverflow.com/questions/4820816/how-to-get-uri-from-an-asset-file – Harry

+0

我發現一個開源可以做到這一點.https://github.com/nostra13/Android -Universal-Image-Loader – CoolEgos

回答

0

您可以通過android中的java代碼以編程方式將圖像從集合添加到圖像視圖。代碼如下:

ImageView image = (ImageView) findViewById(R.id.imageView1); 
AssetManager assetManager = getAssets(); 
     InputStream istr; 
     try { 
      istr = assetManager.open("vishal.jpg"); 
      Bitmap bitmap = BitmapFactory.decodeStream(istr); 
      image.setImageBitmap(bitmap); 
      istr.close(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
+0

但我得到'assets://icon/photography1'.i想加載使用它。 – CoolEgos

+0

將open(「vishal.jpg」)替換爲open(「資產文件夾中的任何路徑」); – Vishal

+0

thx,但是我可以打開像'/icon/visha1.jpg'這樣的文件,只在'assets'中創建一個文件'icon'。 – CoolEgos