用 Picasso 叠加图像

Overlay images with Picasso

我有一张主产品图片,它总是显示在我的 ImageView 中。现在有可能有几个叠加(与原始图像大小相同,但有很多透明区域)。

所有这些图像都来自远程 URL。例如:

Main image

Overlay

是否可以将它们全部加载到一个ImageView

您可以自定义 ImageViewload bitmaps with Picasso,然后在 canvas 上绘制这些位图:

@Override
protected void onDraw(final Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawBitmap(bitmap1, 0, 0, null); // lower image
    canvas.drawBitmap(bitmap2, 0, 0, null); // upper image
}

你可以试试这个xml

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

    <ImageView
        android:id="@+id/image"
        android:layout_width="60dip"
        android:layout_height="60dip"
        android:adjustViewBounds="true"
        android:layout_centerInParent="true"
        android:scaleType="centerCrop" />

    <ImageView
        android:id="@+id/imagef"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        android:background="@drawable/ph_bg" />

</RelativeLayout>