Picasso 加载横向图像但不将纵向图像加载到标记的信息中 window

Picasso loads landscape image but doesn't load portrait into marker's info window

我有一张地图 activity,我想在其中为我的标记定制信息 window。 在那个 window 我想从文件加载图片,并添加一些额外的文本(我稍后会添加)。

问题是,当我有一个横向模式的图片文件时,照片会以正确的尺寸加载并显示在标记的信息 window 中。 但是,如果文件是纵向模式,信息 window 会显示正确的尺寸(实际上是纵向),但不会显示图片。 我检查了人像图片文件是否存在,文件路径正确,但我找不到人像图片为什么不显示。

这是我的代码:

        // 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>

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

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