Created
January 13, 2014 14:18
-
-
Save ixiyang/8400996 to your computer and use it in GitHub Desktop.
copy view from animationadapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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