我有一个自定义视图类(用于绘图的画布)。当我希望它占据整个屏幕时,我实例化该类并像这样调用 setContentView:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawingPanel = new DrawingPanel(this);
setContentView(drawingPanel);
}
但是,当我希望屏幕基于 xml 布局 (activity_make.xml) 并带有 2 个元素、一个按钮和一个用于绘图画布的占位符时,如何将我的自定义视图“粘贴”到视图占位符中?
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?
}
还是有更好的方法来解决这个问题?也感谢有关此文档的链接!