create Drag Outline on View - Android User Interface

Android examples for User Interface:View

Description

create Drag Outline on View

Demo Code


//package com.java2s;

import android.graphics.Bitmap;
import android.graphics.Canvas;

import android.graphics.Rect;
import android.graphics.Region.Op;

import android.view.View;

public class Main {
    public static Bitmap createDragOutline(View source) {
        Canvas canvas = new Canvas();
        int imgW = source.getWidth();
        int imgH = source.getHeight();
        final Bitmap b = Bitmap.createBitmap(imgW, imgH,
                Bitmap.Config.ARGB_8888);
        canvas.setBitmap(b);//from  www  .j a v  a  2  s.c o m
        Rect clipRect = new Rect();
        source.getDrawingRect(clipRect);
        canvas.save();
        canvas.translate(-source.getScrollX(), -source.getScrollY());
        canvas.clipRect(clipRect, Op.REPLACE);
        source.draw(canvas);
        canvas.restore();
        canvas.setBitmap(null);
        return b;
    }
}

Related Tutorials