一个图像视图中具有不同比例类型的两个位图

Two bitmaps in one imageview with different scaletype

你好,我有一个简单的问题..

我需要将两个不同的位图放入一个图像视图中。但第一个位图必须在 ImageView.ScaleType.FIT_XY 上,第二个位图必须在 ImageView.ScaleType.FIT_CENTER

我从网上找到了一些方法,但都使用相同的刻度类型。

感谢您的建议。

我需要在 imageview 中有这个..(图片没有 pageview..)

////////// 解释我为什么需要。

@Override public Object instantiateItem(ViewGroup view, int position) {
    ImageView img= new ImageView(view.getContext());
    ImageLoader.getInstance().displayImage(listKone.get(pozicia).getCestaObrazok(), img);

    //
    ImageLoader.getInstance().displayImage(listKone.get(pozicia).getCestaObrazok(), img2);


    BitmapDrawable drawable = (BitmapDrawable) img2.getDrawable();
    Bitmap bitmap = null;
    try {
        bitmap = drawable.getBitmap();
    } catch (NullPointerException e){
    }



    while ((drawable==null)||(bitmap==null)) {
        ImageLoader.getInstance().displayImage(listKone.get(pozicia).getCestaObrazok(), img2); // Default options will be used

        drawable = (BitmapDrawable) img2.getDrawable();
        bitmap = drawable.getBitmap();
    }
    Bitmap blurred = blurRenderScript(act, bitmap, 25);



    view.addView(img, ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    return img;
}

return img; 我需要一个图像视图中的位图模糊和位图位图。但是bitmap Blured FIT_XY 和bitmap bitmap center。我需要像图片中那样查看 ↑

一对一使用两个imageview。

    <layer-list>
   <item>
        <bitmap android:src="@drawable/bitmap1"
            android:gravity="fill" />
    </item>
    <item>
        <bitmap android:src="@drawable/bitmap2"
            android:gravity="center" />
    </item>
</layer-list>

您可以像这样使用 LayerDrawable 将两个图像设置在另一个图像上,然后在 ImageView 中设置它们

我找到了我编辑的方法..

public static Bitmap CombineImages(Bitmap background, Bitmap foreground)  {

    int width = (int) act.getResources().getDimension(R.dimen.imageH);
    int height = (int) act.getResources().getDimension(R.dimen.imageH);
    Bitmap cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas comboImage = new Canvas(cs);
    background = Bitmap.createScaledBitmap(background, width, height, true);
    comboImage.drawBitmap(background, 0, 0, null);

    float Fwidth = foreground.getWidth();
    float Fheight = foreground.getHeight();

    if (Fheight>Fheight){
        Fwidth=(height/Fheight) * Fwidth;
        Fheight=height;
        foreground = Bitmap.createScaledBitmap(foreground,(int) Fwidth,(int) Fheight, true);
    }

    if (Fheight<=Fheight){
        Fheight=(width/Fwidth)*Fheight;
        Fwidth=width;
        foreground = Bitmap.createScaledBitmap(foreground,(int) Fwidth,(int) Fheight, true);
    }

    float top = (height-Fheight)/2;
    float left = (width-Fwidth)/2;

    comboImage.drawBitmap(foreground, left, top, null);

    return cs;
}

你有没有更好的解决方案写。广告 iterim 使用此解决方案。但如果将来有更多的图像将是无效的。