Skip to content

Instantly share code, notes, and snippets.

@ixiyang
Created January 13, 2014 14:18
Show Gist options
  • Save ixiyang/8400996 to your computer and use it in GitHub Desktop.
Save ixiyang/8400996 to your computer and use it in GitHub Desktop.
copy view from animationadapter
public class ViewCopy extends View {
private Bitmap viewCopy;
public ViewCopy(View view) {
super(view.getContext());
copyView(view);
measure(MeasureSpec.makeMeasureSpec(view.getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(view.getHeight(), MeasureSpec.EXACTLY));
layout(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
private void copyView(View view) {
Bitmap b = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
view.draw(c);
viewCopy = b;
}
@Override protected void onDraw(Canvas canvas) {
canvas.drawBitmap(viewCopy, 0.0f, 0.0f, null);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment