毕加索加载了风景图像,但没有将肖像加载到标记的信息窗口中

时间:2018-06-13 08:00:42

标签: android google-maps picasso marker

我有一个地图活动,我希望我的标记有自定义信息窗口。 在那个窗口中,我想从文件中加载图片,并添加一些额外的文本(稍后我会添加)。

问题是,当我在横向模式下有一个图片文件时,照片会加载并显示在具有正确尺寸的标记信息窗口中。 但是,如果文件处于纵向模式,则信息窗口将显示正确的尺寸(实际上是纵向),但没有显示图片。 我检查了肖像图像文件是否存在,它是否有正确的文件路径,但我无法找出为什么肖像图片不显示。

这是我的代码:

        // Initializing the custom info window as per info_window.xml
        if (mMap != null) {
            mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
                @Override
                public View getInfoWindow(Marker marker) {
                    return null;
                }

                @Override
                public View getInfoContents(Marker marker) {

                    View view = getLayoutInflater().inflate(R.layout.info_window, null);
                    mImageView = view.findViewById(R.id.markerImageView);

                    for (Picture picture : mPictureList) {
                        if (picture.getMarker().equals(marker)) {
                            String path = picture.getPicturePath();
                            int width = 160;
                            int height = 90;
                            ExifInterface data = null;
                            try {
                                data = new ExifInterface(path);
                                String orientation = data.getAttribute(ExifInterface.TAG_ORIENTATION);
                                // 1 for landscape, 3 for landscape upside down
                                // 6 for portrait, 8 is portrait upside down
                                if (orientation.equalsIgnoreCase("6") || orientation.equalsIgnoreCase("8")) {
                                    width = 90;
                                    height = 160;
                                }
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                            // setting the new dimensions in dp
                            mImageView.getLayoutParams().height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, height, getResources().getDisplayMetrics());
                            mImageView.getLayoutParams().width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, width, getResources().getDisplayMetrics());
                            mImageView.requestLayout();

                            Picasso.with(MapsActivity.this)
                                    .load("file://" + path)
                                    .resize(width, height)
                                    .centerCrop()
                                    .into(mImageView);
                        } else {
                            Log.d(TAG, "getInfoContents: Didn't find any picture with that marker");
                        }
                    }
                    return view;
                }
            });
        }

和info_window.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

<ImageView
    android:id="@+id/markerImageView"
    android:layout_width="160dp"
    android:layout_height="160dp"/>

</LinearLayout>

1 个答案:

答案 0 :(得分:0)

我终于找到了解决这个问题的方法。 我使用的是最新版本的picasso 2.3.2,它有显示图像的问题(按照https://github.com/square/picasso/issues/530) 我切换到2.2.0版本,问题解决了。

P.S。版本2.4.0应该解决上述问题。