[英]onDraw of custom view not being called
I have a custom view extending ImageView. 我有一个扩展ImageView的自定义视图。 onDraw() is never called. 永远不会调用onDraw()。
Nothing complicated: 没什么复杂的:
public class NVGlobeView extends ImageView{
I have all 3 constructors: 我有所有3个构造函数:
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. 我忽略了onMeasure并强制使用了固定大小,以确保视图的尺寸不为零。 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. 我知道我的视图已添加到布局中,因为调用了onMeasure(),因此我可以逐步检查它以确认大小设置正确。 I've also validated it with the heirarchy viewer on an AVD. 我还通过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() 最后,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? 有什么想法我错过了吗?
一个猜测,也许您返回的测量结果是该视图不占用可见空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.