I've created the child of RelativeLayout. In its constructor I called:
public CanvasHolder(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layoutInflater.inflate(R.layout.canvas_holder, this);
this.draw(new Canvas());
}
And then override method onDraw():
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
black.setARGB(255, 0, 0, 0);
black.setAntiAlias(true);
int halfWidth = this.getWidth() / 2;
int height = this.getHeight();
canvas.drawLine(0, 0, halfWidth, height, black);
}
No line has been appeared on the view. Also, I tried not to call "this.draw()", but nothing happened.
I've discovered that halfWidth and height equals 0. Why?
P.S. even if I set width and height statically, nothing will change. If you don't mind, take a look on this sample application: why nothing is drawn? http://androidforums.com/attachment.php?attachmentid=21715&stc=1&d=1315232946