I have a custom view extending ImageView. onDraw() is never called.
Nothing complicated:
public class NVGlobeView extends ImageView{
I have all 3 constructors:
public NVGlobeView(Context context) {
this(context, null);
}
public NVGlobeView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public NVGlobeView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
I've overidden onMeasure and forced a fixed size to ensure that the view does not have a zero dimension. I know that my view is added to the layout since onMeasure() is called and I can step through it to verify the size is set correctly. I've also validated it with the heirarchy viewer on an AVD.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//setMeasuredDimension(getMeasuredWidth(), getMeasuredHeight());
DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
setMeasuredDimension(dm.widthPixels-50,dm.heightPixels-100);
}
Finally, the onDraw()
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
}
I put a breakpoint on the super call and it's never reached.
Here's the associated activity code.
setContentView(R.layout.nvglobeview);
NVGlobeView globeView = (NVGlobeView)findViewById(R.id.globeView);
globeView.invalidate();
Any ideas what I've missed?