0

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?

4

1 回答 1

0

猜测,也许您返回的测量结果是视图不占用可见空间。

于 2013-01-25T17:59:13.660 回答