如何将URL图像延迟加载到谷歌地图标记图标

Ell*_*Lam 5 android google-maps image google-maps-markers android-maps-v2

我正在使用谷歌地图实用程序库演示代码,并更改为使用毕加索进行图像加载.

我的问题是跟随捕获.

毕加索无法加载图像并使用占位符图像

毕加索无法加载图像并使用占位符图像

放大和缩小后,刷新标记.可以加载图像

放大和缩小后,刷新标记. 可以加载图像.

我的问题与谷歌地图V2延迟加载标记图像相同 但是我无法从答案得到帮助,我卡住了Bitmap bitmap = thumbCache.get(url); 我也尝试了毕加索onSuccess回调,但也对它感到厌烦.

下载URL图像完成后如何刷新制造商图标?我可以使用另一个URL图像加载器库.

/**
 * Draws profile photos inside markers (using IconGenerator).
 * When there are multiple people in the cluster, draw multiple photos (using MultiDrawable).
 */
private class PersonRenderer extends DefaultClusterRenderer<Person> {
    private final IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
    private final IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
    private final ImageView mImageView;
    private final ImageView mClusterImageView;
    private final int mDimension;

    public PersonRenderer() {
        super(getApplicationContext(), getMap(), mClusterManager);

        View multiProfile = getLayoutInflater().inflate(R.layout.multi_profile, null);
        mClusterIconGenerator.setContentView(multiProfile);
        mClusterImageView = (ImageView) multiProfile.findViewById(R.id.image);

        mImageView = new ImageView(getApplicationContext());
        mDimension = (int) getResources().getDimension(R.dimen.custom_profile_image);
        mImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension));
        int padding = (int) getResources().getDimension(R.dimen.custom_profile_padding);
        mImageView.setPadding(padding, padding, padding, padding);
        mIconGenerator.setContentView(mImageView);
    }

    @Override
    protected void onBeforeClusterItemRendered(Person person, MarkerOptions markerOptions) {
        // Draw a single person.
        // Set the info window to show their name.

        Picasso.with(getApplicationContext())
                .load(person.profileUrl)
                .placeholder(R.drawable.ic_launcher)
                .error(R.drawable.ic_launcher)
                .resize(64, 64)
                .centerCrop()
                .into(mImageView);

        Bitmap icon = mIconGenerator.makeIcon();
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon)).title(person.name);
    }

    @Override
    protected void onBeforeClusterRendered(Cluster<Person> cluster, MarkerOptions markerOptions) {
        // Draw multiple people.
        // Note: this method runs on the UI thread. Don't spend too much time in here (like in this example).
        List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
        int width = mDimension;
        int height = mDimension;

        for (Person p : cluster.getItems()) {
            // Draw 4 at most.
            if (profilePhotos.size() == 4) break;
            ImageView cImageView = new ImageView(getBaseContext());

            Picasso.with(getApplicationContext())
                    .load(p.profileUrl)
                    .placeholder(R.drawable.ic_launcher)
                    .error(R.drawable.ic_launcher)
                    .resize(64, 64)
                    .centerCrop()
                    .into(cImageView);

            Drawable drawable = cImageView.getDrawable();
            drawable.setBounds(0, 0, width, height);
            profilePhotos.add(drawable);

        }
        MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
        multiDrawable.setBounds(0, 0, width, height);

        mClusterImageView.setImageDrawable(multiDrawable);
        Bitmap icon = mClusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
    }
Run Code Online (Sandbox Code Playgroud)