I have a custom view class (a canvas for drawing). When I want it to take up the whole screen, I instantiate the class and call setContentView like so:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawingPanel = new DrawingPanel(this);
setContentView(drawingPanel);
}
However, when I want the screen to be base on an xml layout (activity_make.xml) with say 2 elements, one button and a placeholder for the drawing canvas, how do ‘stick’ my custom view into the view placeholder?
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_make); // the layout which has a button and a placeholder view
drawingPanel = new DrawingPanel(this); // instantiating my canvas
View drawPanelPlaceholder = (View) findViewById(R.id.drawingview);
// how do i stick the drawingPanel into the drawPanelPlaceholder?
}
Or is there a better way to approach this? Links to documentation regarding this are also appreciated!
If your DrawingPanel class extends View you can do something like this,
In your xml declare this custom component with its package name,
Please note that, com.myview.DrawingPanel is just a name that I have used to demonstrate. But make sure you use the same package name in which you have your DrawingPanel.class.
And now in your onCreate,