Skip to content

Instantly share code, notes, and snippets.

@maxim-petlyuk
Created August 23, 2018 10:04
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxim-petlyuk/5f4d4eb70ab1cbac9b5af34b2fbb732f to your computer and use it in GitHub Desktop.
Save maxim-petlyuk/5f4d4eb70ab1cbac9b5af34b2fbb732f to your computer and use it in GitHub Desktop.
Draw view from the existing original view
public class CloneView extends View {
private View mSource;
public CloneView(Context context) {
super(context);
}
public CloneView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public CloneView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public View getSource() {
return mSource;
}
public void setSource(View source) {
mSource = source;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
if (mSource != null) {
mSource.draw(canvas);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment