► 圖層是疊圖
► 貼圖模式
Resources r = getResources(); Drawable[] layers = new Drawable[2]; layers[0] = r.getDrawable(R.drawable.map1); layers[1] = r.getDrawable(R.drawable.user); LayerDrawable layerDrawable = new LayerDrawable(layers); imageView.setImageDrawable(layerDrawable);
► 貼圖模式
/** * 疊圖 * @param background 背景 * @param foreground 前景 * @param x 前景x位置 * @param y 前景y位置 * @return */ public static Bitmap combineBitmap(Bitmap background, Bitmap foreground, float x, float y) { if (background == null) return null; int bWidth = background.getWidth(); int bHeight = background.getHeight(); int fWidth = foreground.getWidth(); int fHeight = foreground.getHeight(); Bitmap newmap = Bitmap.createBitmap(bWidth, bHeight, Config.ARGB_8888); int unitX = bWidth/100; int unitY = bHeight/100; Canvas canvas = new Canvas(newmap); canvas.drawBitmap(background, 0, 0, null); canvas.drawBitmap(foreground, unitX * x -(fWidth/2), unitY * y-(fHeight/2), null); canvas.save(Canvas.ALL_SAVE_FLAG); canvas.restore(); return newmap; }