2015-04-21 25 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