To visually clone another view. This does not make a functional copy of the view – no hit areas or other behavior or state is cloned. This is a simple View instance that draws the pixels of the source `View` and positions them appropriately.

package com.moagrius.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;


/**
 * Created by Mike Dunn on 8/9/17.
 */
public class CloneView extends View {

  private View mViewToClone;

  public CloneView(Context context) {
    super(context);
  }

  public CloneView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public CloneView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
  }
  
  public CloneView(View view) {
    super(view.getContext());
    setViewToClone(view);
    invalidate();
  }

  public View getViewToClone() {
    return mViewToClone;
  }

  public void setViewToClone(View viewToClone) {
    mViewToClone = viewToClone;
  }

  @Override
  protected void onDraw(Canvas canvas) {
    if (mViewToClone != null) {
      canvas.save();
      canvas.translate(-mViewToClone.getScrollX(), -mViewToClone.getScrollY());
      mViewToClone.draw(canvas);
      canvas.restore();
    }
  }

}