【问题标题】:How to display image in LayoutInflater如何在 LayoutInflater 中显示图像
【发布时间】:2015-03-09 11:37:52
【问题描述】:

这个问题可能有点明显,但情况如下:

在我的应用程序(googleMaps v2)中,我有一个自定义标记,它有一个图像视图(从相机意图拍摄的图像)。因此,一旦应用程序在 SQlite 数据库中重新启动,我已经保存了再次加载图像所需的所有信息。但问题是,当尝试将图像加载到布局充气机时,没有显示任何内容,但是当我在我的活动中创建 Imageview(即不在布局充气机中)时,图像会显示出来,但显然在我没有的地图上'不想。

所以这是我从相机意图返回时在 ImageView 中加载图像的代码(这有效)

@Override
  public View getInfoContents(Marker marker)
    {
  View v  = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
  ImageView markerIcon = (ImageView) v.findViewById(R.id.PicView);
Bitmap bitmap = myMarkersHash.get(marker.getId());
markerIcon.setImageBitmap(bitmap);

然后当应用重启时尝试从数据库加载:

filep = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_FILEPATH));
....
View view  = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView image = (ImageView) view.findViewById(R.id.PicView);
Bitmap myImage = BitmapFactory.decodeFile(filep);
image.setImageBitmap(myImage);

然后什么都不显示

谁能告诉我为什么图片不显示? PS没有错误消息或任何我可以添加到这个问题的东西。

【问题讨论】:

  • 您确认 filep 返回正确的值了吗?你的代码在哪里使用了 filep?

标签: android image sqlite


【解决方案1】:

如果您将文件路径存储在filep中,那么它应该是:

位图 myImage = BitmapFactory.decodeFile(filep);

针对我下面的评论,您可以尝试添加配置选项 ARGB_8888 来保留文件,例如:

filep = arg1.getString(arg1.getColumnIndex(LocationsDB.FIELD_FILEPATH));
....
View view  = getLayoutInflater().inflate(R.layout.infowindow_layout, null);
ImageView image = (ImageView) view.findViewById(R.id.PicView);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap myImage = BitmapFactory.decodeFile(filep, options);
image.setImageBitmap(myImage);

【讨论】:

  • 对不起,这是一个错字,我已经稍微更改了代码,但仍然没有显示任何内容。
  • 显然,如果您的应用中出现这种情况,其他人在从 SD 卡中提取时会遇到问题。看到这个帖子:stackoverflow.com/questions/8710515/…
  • 谢谢,但问题是当我在与谷歌地图相同的 XML 布局中使用 Imageview 时会显示图像,但是当我使用布局充气器时,图像不会显示。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2017-04-06
  • 2013-01-22
  • 2012-06-28
  • 2016-02-05
  • 2020-10-17
  • 2016-07-23
相关资源
最近更新 更多